You are not logged in.

#1 2015-03-31 11:56:29

Soukyuu
Member
Registered: 2014-04-08
Posts: 854

Backup / using tar+7z: am I doing this right?

Basically, before I get to the point where I have to restore a backup and potentially find out I can't, I want to make sure my procedure is correct.

I've used to use rsync to backup the system, but it has some drawbacks, like not being able to store the backup on a non-linux FS. Using just 7zip has the same problem - it does not save linux permissions.
So as a workaround, I use tar to pack the files and pipe the output to 7za:

cur_date=$(date +"%y%m%d")
echo $cur_date
tar cf - /* --exclude={"/dev/*","/home/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/var/tmp/*","/var/lib/systemd/coredump/*","/backup/*"} | 7za a -mx -mmt=4 -si /tmp/arch-backup-$cur_date.tar.7z

Home is on another partition, so I don't back it up.

So, to extract the backup, this site (where I got the idea from) says to use

7za x -so directory.tar.7z | tar

From what I understand, this will simply extract, overwriting any changed files. It won't do a mirroring operation though - remove files that are not in the archive. Is there a way to do that with tar?


[ Arch x86_64 | linux | Framework 13 | AMD Ryzen™ 5 7640U | 32GB RAM | KDE Plasma Wayland ]

Offline

#2 2015-03-31 12:33:38

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Backup / using tar+7z: am I doing this right?

At least bsdtar has

--keep-newer-files
              Don't replace existing files that are newer than their archive copies.

If you want to remove files, use 'rm' first, extract the archive later.

Offline

#3 2015-03-31 12:42:22

Soukyuu
Member
Registered: 2014-04-08
Posts: 854

Re: Backup / using tar+7z: am I doing this right?

tar has the same option btw, but that would kind of defeat the purpose of restoring an older version of the files.
I suppose to use 'rm' I'd have to boot into a live system first, mount the system partition and wipe it, then restore.

I've read something about having to add 'p' to the 'cf' part to really keep permissions, but man says

-p, --preserve-permissions, --same-permissions
              extract information about file permissions (default for superuser)

So running the script in my first post with sudo should preserve permissions even if I don't add the 'p' option.

Last edited by Soukyuu (2015-03-31 12:42:38)


[ Arch x86_64 | linux | Framework 13 | AMD Ryzen™ 5 7640U | 32GB RAM | KDE Plasma Wayland ]

Offline

Board footer

Powered by FluxBB