简体   繁体   中英

Bash script to backup modified file in a particular folder structure

I have a folder structure from there i am backing up files which are modified Below is folder structure

/home/aaditya/customer/jiva/foo/bar/File1.txt

Using below command i want to backup File1.txt file

 cd /home/aaditya/customer/jiva/foo/bar
 tar -zcvf archive_backup_folder.tar.gz File1.txt

But my problem statement is that when i unzip the tar archive_backup_folder, File1.txt should be there inside customer/jiva/foo/bar/File1.txt not only File1.txt
Can anybody help me how to do that.

Just do:

cd /home/aaditya/
tar -zcvf archive_backup_folder.tar.gz customer/jiva/foo/bar/File1.txt

That is, include the path structure in the archive.

You can try something like this

TIME=`date +%b-%d-%y`
FILENAME=backup-$TIME.tar.gz
SRCDIR= directory or file that has to be backed up
DESDIR= place where you need to store it
tar -cpzf $DESDIR/$FILENAME $SRCDIR
 cd /home/aaditya/
 find customer -mtime -1 -exec tar -rvf test.tar {} \;

the "find" command will find out all files modified within 1 day and for each of them, run "tar -rvf test.tar the_file" to add it to test.tar (you way want to "rm -f test.tar" before running the "find" command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM