tutorials on tar and date
I've been looking all over for tutorials on tar, but I can't seem to find one that I can understand. For instance, if I attempt to run the command:
tar --directory=$HOME/Documents/WiPs fz --create myfirstbackup.tar.gz I get this response tar: You must specify one of the `-Acdtrux' options Try `tar --help' or `tar --usage' for more information. I know what I'm doing wrong is inately obvious, but I can't see it at this point. What I want to do is get this to the point where I can cron this into a job that runs automatically and makes a file named based on the date (eg backup01132007.tar.gz). Update: found out that I needed to switch the directory and the filename around. Seems a bit backwards to me, from the programs I've come across, but hey it works. Now two questions: 1. How do I compress down the directories so they only include the ones with files and don't create "home","jmeyer" when they are only part of the name. 2. How can I extract the month, day and year from date (I've tried +FORMAT, doesn't seem to work) |
You can use ~ instead of $HOME, that way the shell can still autocomplete for you when you press tab.
The man or info pages are always a good place to start for help on a program ("man <programname>" or "info <programname>"). With date, are you literally typing +FORMAT? FORMAT is a placeholder for the format you want, so do e.g. "date +%A" prints "Monday". This is in the man page for date, and strftime (as led to by the date man page). |
Quote:
Code:
tar --directory=$HOME/Documents/WiPs --create --gzip --file myfirstbackup.tar.gz fz |
One of the things that I see is that the -f option is not followed by the filename.
tar -czf myfile.tar *.php is OK but tar -cfz myfile.tar *.php is not correct. |
Cool. Thanks for the help.
I got the format thing (sometimes you follow instructions a leetle too literally), now just need to learn how to store those things into variables to create the filename. |
Quote:
Quote:
Quote:
Quote:
Code:
date +"%H %M %S %e %B %Y" Code:
date +"%H:%M:%S %e %B %Y" Code:
date +"%H:%M:%S %e %B %Y %a" Code:
date -d tomorrow |
If you use the find command to provide the filelist to tar, you can prune -empty directories.
The GNU findutils and tar source contain the .texi source for the info manuals. You might consider producing pdf or dvi documents from the source. Often there is a "make pdf" or "make ps" target after running "./configure". Some of the manuals are very long and comprehensive. If memory serves, the tar source ( I was going to write tar tarball but decided that would be too cute ) has a manual "Backing Up Files". |
Quote:
An example: if you usually ran Code:
tar ... -f /home/jmeyer/example Code:
cd /home/jmeyer && tar ... -f example |
Okay, I finally fixed all of the errors, I think. Here's the script:
myfilename="backup$(date +%m%d%y).tar.gz" #echo $myfilename cd $HOME/Documents && tar czf $HOME/$myfilename WiPs Now I just need to cron this thing. |
All times are GMT -5. The time now is 03:49 AM. |