Results 1 to 3 of 3
I am running a web server and want to create a script to back it up.
I created a shell script that seems to do what I want but when ...
- 01-13-2010 #1Just Joined!
- Join Date
- Jan 2010
- Location
- Tampa, Florida
- Posts
- 3
tar using --exclude and -C dir
I am running a web server and want to create a script to back it up.
I created a shell script that seems to do what I want but when I look at the tar.gz file produced by the script it seems incomplete.
Here is what I am using to backup the server:
/bin/tar zcvpf /media/terabyte-usb/www-full-backup-`date '+%A'`.tar.gz --directory / --exclude /media/* --exclude mnt/* --exclude /proc/* .
When I run it manually (not from a script) I see this message: "/bin/tar: Removing leading / from member names"
I believe by default tar does this so I assume this is normal.
In any case, when I look at the output it seems to have directories that I excluded. What am I doing wrong?
This shows some of the directories that I wanted to exclude from the backup in the output:
#tar tzf /media/terabyte-usb/www-full-backup-Tuesday.tar.gz
proc/tty/
proc/tty/drivers
proc/tty/ldiscs
proc/tty/driver/
proc/tty/driver/serial
proc/tty/ldisc/
proc/uptime
proc/version
proc/vmstat
If you have any suggestion on how to backup this server completely excluding what I dont need, i'd be much appreciative.
- 01-14-2010 #2Linux Newbie
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 243
help with tar
If this is the exact command you used:
I am a bit surprised that it did anything at all.Code:/bin/tar zcvpf /media/terabyte-usb/www-full-backup-`date '+%A'`.tar.gz --directory / --exclude /media/* --exclude mnt/* --exclude /proc/*
First thing: the --directory tag will change directories before looking for the files you wish to back-up, and then you must specify which files within that directory that you want to archive, so I you won't need to use that tag. Second thing: the --exclude doesn't need the wildcard character to work, it excludes the directory and hence also it's entire contents, unless e.g. you are trying to exclude files with particular extensions. So --exclude=media --exclude=mnt will work fine, but you could also do:I think the command you are trying to do should work like this:Code:"--exclude=*.tgz" "--exclude=*.tar.gz"
Also, I would exclude the "/dev", "/sys", and "/tmp" directories if you are going to tar the root directory.Code:tar cvzpf place-to-put-archive.tgz / --exclude=media --exclude=mnt --exclude=proc
Actually, I would just create a text file listing all of the directories I would like to exclude, called "dont-backup.txt", and then use the "--exclude-from" tag, for example:.Code:tar czvf my-directory.tgz my-directory --exclude-from=dont-backup.txt "--exclude=*.tar.gz"
Or, I would create a text file listing the directories I would want to back-up and run this command:I hope that helps, good luck!Code:tar czvf my-archive.tgz --directory base-directory `cat files-in-the-base-directory-to-be-backed-up.txt`
- 01-14-2010 #3Just Joined!
- Join Date
- Jan 2010
- Location
- Tampa, Florida
- Posts
- 3
Thank you for your help. I am running it now to test.
I do appreciate your time.


Reply With Quote