niels Posted February 15, 2011 Share Posted February 15, 2011 Hey everybody, I'm writing a script to automaticaly backup a directory with the tar command. Now I tried several different approaches to use relative paths but I can't get it working. I always get the following error : tar: Removing leading `/' from member names I tried the tar -cjfP $TAR_FILE $DATA, or tar -cjfP $TAR_FILE -C /$DATA and my last approach is creating a textfile with each file name to add to the tar file, like this : # --- BEGIN --- DATA="/CVS_Repository/ErikStevensBackUp" DATA_LIST="/Backups/backup_list.txt" TAR_FILE="/Backups/ErikStevensBackup-`date +"%d-%m-%Y"`.tar.bz2" # first remove old backup rm -f /Backups/ErikStevensBackup*.*.* # Create dataList find $DATA -depth -print > $DATA_LIST # create backup with date tar -cjfTP $TARFILE $DATA_LIST # Remove old data list file rm -f $DATA_LIST # --- END --- Anybody has a answers for my problem ? I'm using Ubuntu 10.04 Server edtion. Thanks a lot in advance. Regards, Niels Quote Link to comment Share on other sites More sharing options...
Jason Cooper Posted February 16, 2011 Share Posted February 16, 2011 Now I tried several different approaches to use relative paths but I can't get it working. I always get the following error : tar: Removing leading `/' from member names Don't worry about the error, tar is just telling you that it is removing the / from the start of the files. So if you have asked tar to store /etc/ it will store the files in the tar as etc/passwd etc/shadow ... This is a good thing or you make it very easy to overwrite things accidentally when extracting the tar file. If you really want to store the / at the start of the filename then use either -P or --absolute-names, but I don't think you will want to do that. If you really want to get rid of the error but keep the relativity of the filenames then try something like # --- BEGIN --- DATA="CVS_Repository/ErikStevensBackUp" TAR_FILE="Backups/ErikStevensBackup-`date +"%d-%m-%Y"`.tar.bz2" # first remove old backup rm -f /Backups/ErikStevensBackup*.*.* # Change to the root directory so we can reach all the files we need relatively. (man pushd and popd for more info) pushd / # create backup with date tar -cjfTP $TARFILE $DATA # Pop us back to where we were popd # --- END --- Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.