1

I am not a great linux user, and am just attempting to backup my server files in case of a drive failure. I currently have an SSD running docker containers for a media server, and the media is stored on a ZFS pool of 4 drives in a RAIDZ array. I am attempting to figure out how to rsync my crontab directory to the ZFS pool, and possibly also put it onto a usb to make sure my .env files don't get lost if the SSD fails. I don't know if I worded all of what I'm trying to get across correctly, so sorry! I suppose this would make more sense to just do as /home /mnt (name of the zpool).

rsync -av --delete /home /mnt- 

does this command look correct?

Below is what my Docker backup cronjob looks like, as well as the ZFS scrub.

# m h  dom mon dow   command
0 2 * * * /home/<USER>/.docker/main.sh -b max

# zpool scrub every month
0 2 1 * * /sbin/zpool scrub mnt
0 13 1 * * /sbin/zpool status

Thanks in advance!

1

If you are looking to use rsync to back up files on a regular base you probably want to make some changes. --delete will remove the file you have deleted which means if you accidentally delete all your files and then rsync -av --delete /home /mnt- runs it will remove all of your backups. If all you want to do is to make a copy then this will work, and it will probably save you from a failed disk but you should think about what are you trying to protect your self from. I would suggest taking a look at this post on stack overflow if you are using rsync as your regular backup tool Use rsync for backup without overwrite.

I realize there are many articles out there suggesting to do what you are doing, howtogeek linux.com and while this works great as a one time backup and is even ok if you want to run your backups manually when you know your computer is in a state you are ok with. It is risky to do it automatically. I would suggest using the built-in tool for backups (just search for backup) as it handles the case of deleting or overwriting files by mistake and you can set it up to run weekly/monthly etc and can set how long you want to keep backups for. but if you are just trying to protect from a disk failure what you have is probably ok.

  • So would you recommend using Rsnapshot on the first link? This is a headless server, so I don't have the os version of the built in backup tool. I am mainly attempting to prevent the settings on the SSD from being lost should it fail. The Zpool seems to do that by itself if I am understanding things correctly. – Alschmitt44 Mar 18 at 21:12
  • @Alschmitt44 yes rsnapshot seems like a good option if you are in a headless system. It even deals with cleaning up old snapshots it makes and that can be configured however you want, so you could keep snapshots for weeks or months ect whatever works best for you. They have a FAQ page which looks helpful. I will note that I have not used rsnapshot myself but from what I see of it it looks like a great tool and it will be my goto for this kind of thing. – Jeff Mar 19 at 12:21
  • @Alschmitt44 if this solution solved your problem you asked please upvote and accept the answer. You can accept the answer by selecting the checkmark to the left of the answer. – Jeff Mar 27 at 14:36
0

rsync(1) has an excellent "--archive" option.

It provides my primary means of backup for when I occasionally want to see what my files looked like at some time in the past.

I happen to use a USB permanently plugged into the back of my monitor, but it could instead have been a separate device not physically close to my computer if I wanted a full backup for file-system recovery.

This is the script that I use for backups, running as root at 23:45 each day:

#!/bin/bash -e
# This is run as root at the end of the day
do what you want.

(   echo ">>>>>>>>>>>>>>>>>>>>>>>" $(date)
    today=$(date +%Y-%m-%d)
    month=$(date +%Y-%m)
    # USB backups
    cd /media/ray/Backup-Ray
    rsync --archive --one-file-system --delete --backup --backup-dir="../../$today/etc" "/etc/" "mostrecent/etc/"
    rsync --archive --one-file-system --delete --backup --backup-dir="../../$today/home" --exclude=".config/google-chrome/" --exclude=".cache/" --exclude=".local/share/zeitgeist/" --exclude="Downloads/" "/home/" "mostrecent/home/"
    rsync --archive $today/ $month/
    echo "<<<<<<<<<<<<<<<<<<<<<<<" $(date)
) &>>/home/ray/Log/root.out

exit 0

All changed and deleted files are preserved. It's easy to use the standard unix tools to examine and recover files:

$ cd /media/ray/Backup-Ray
$ ls -l {,*}/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14002 Dec  3 21:04 2018-12-16/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14102 Dec 16 09:28 2018-12-17/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14202 Dec 17 20:47 2018-12-20/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14302 Dec 20 15:12 2018-12-25/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14402 Dec 25 21:21 2018-12-26/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14402 Dec 25 21:21    2018-12/home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14452 Dec 26 18:43        /home/ray/public/Log/wait.xhtml
-rw-r--r-- 1 ray ray 14452 Dec 26 18:43 mostrecent/home/ray/public/Log/wait.xhtml

Only the "mostrecent" directory is large.

The monthly accumulation directory (2018-12) contains the most recent changes throughout the month. It isn't necessary to do this step, but when I need to save space it allows me to delete all the daily updates for that month (A year from now I might care what things looked like at the end of December, but not so much how things changed within the month.)

Obviously you'd need to change the frequency, timestamps, etc., but the same mechanism should provide regular backups.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.