Incremental Backup using tar for more than one path

Hi everyone;

I need to create a shell script for full and incremental backup purposes. for incremental backup only for one folder (test1) located in /home/test1 syntax below works fine and have no problem:

 tar -cvf /home/backup/backup-0.tar.gz -g /home/test1/test.snar /home/test 

Problem is here when I want to create a backup of two different folder at the same time using on line command. for example if I want to create incremental backup for two folder (test1,test2) located in /home/test1 and /etc/test2 what would be syntax??? should I have test.snar file in both folders or what???

Thanks for your kindly helps in advanced.

Typically you would use one snapshot file for the whole backup instead of trying to keep a separate one for each folder within a backup. Think of the snapshot file as a record of what versions of files are within the backup, not information about the directories. Name you snapshot like your backup file and keep them together, eg:

tar -cvf /home/backup/backup-0.tar.gz -g /home/backup/backup-0.ss /home/test1 /etc/test2

Later when you come to do a level-1 backup of the same directories you would then do:

cp /home/backup/backup-0.ss /home/backup/backup-1.ss
tar -cvf /home/backup/backup-1.tar.gz -g /home/backup/backup-1.ss /home/test1 /etc/test2

Worked perfectly .

thanks

---------- Post updated at 02:27 AM ---------- Previous update was at 02:21 AM ----------

on more question please:

when i try restore backup using tar -xvf all will be restored in current path. you know how it works if i want to restore and overwrite each extracted file(s) and folder(s) to their own original path (where they were when we created the backup)?

thanks in advanced for your pation

That behaviour is on purpose so you have the chance to do a last check before overwriting the original files.
If you cd to the top of the relative path from where you took the backup, it should overwrite on restore.

Using the -P or --absolute-names when creating the archive will disable this feature.

But, as RudiC points out, it is quite painful if archives have full pathnames as it is difficult to restore files to a different location for comparison/verification purposes before overwriting the existing file(s).

1 Like

So , if our archive contain backup from different paths better choice would be extract archive in current folder, make sure all are good and then overwrite all extracted folders manually to where they were backed up from.