Linux – How to tar Rsnapshot backup files automatically

backuplinuxrsnapshot

I am using Rsnapshot to backup my server files to a remote server. To minimize the file size, I want to tar the backup files, but I don't know how to do it with Rsnapshot.

Can anyone help me with this? Any help would be grateful.
Thank You.

Best Answer

You can use the cmd_postexec configuration setting to run a custom script after rsnapshot completes. This script can then do anything you want.

However, tarring the files after the fact will, if anything, increase the disk usage. Probably by a lot. By default, rsnapshot passes options to rsync such that rsync hardlinks any unchanged files to the previous revision of the same file.

  • tar adds some metadata, which normally exists separately (for example, file path/name, permissions, etc.), leading to a marginal increase in disk space usage compared to just keeping the files raw.
  • tar by itself does not do any compression (although you can run the resultant .tar file through a compressor like gzip, bzip2, xz, etc.).
  • By tarring the tree after rsync finishes, you lose the ability to hardlink between revisions, so each backup tree tar file must contain the full content rather than just the difference compared to the previous revision.

The only way around the third point above that I can see would be to tar the entire target directory structure (the one named by snapshot_root in rsnapshot's configuration) but you would then need to untar it before rsnapshot starts running rsync (this can be done through a script executed through cmd_preexec if you really want to do it), then re-tar it afterwards. This will approximately double the peak disk space usage as well as significantly increase the time needed to run through a rsnapshot execution, for no real benefit at all.

Just use rsnapshot the way it was intended. It's easier, and I don't see it having any downsides that would be solved by religiously running tar on the backups.

If you have a specific issue with how rsnapshot keeps the copies, then focus on that, not on tar (which may or may not be a solution to whatever issue you might be having).

Related Topic