Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Location
    Tampa, Florida
    Posts
    3

    Smile 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.

  2. #2
    Linux Newbie
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    243

    help with tar

    If this is the exact command you used:
    Code:
    /bin/tar zcvpf /media/terabyte-usb/www-full-backup-`date '+%A'`.tar.gz --directory / --exclude /media/* --exclude mnt/* --exclude /proc/*
    I am a bit surprised that it did anything at all.

    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:
    Code:
    "--exclude=*.tgz" "--exclude=*.tar.gz"
    I think the command you are trying to do should work like this:
    Code:
    tar cvzpf place-to-put-archive.tgz / --exclude=media --exclude=mnt --exclude=proc
    Also, I would exclude the "/dev", "/sys", and "/tmp" directories if you are going to tar the root directory.

    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:
    Code:
    tar czvf my-archive.tgz --directory base-directory `cat files-in-the-base-directory-to-be-backed-up.txt`
    I hope that helps, good luck!

  3. #3
    Just 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...