0

I would like to have a script that periodically and automatically backs up select system files to my NAS, which I have in my fstab to cifs mounts on boot. Based on the responses from Which Folders To Include In backup?, I put together the following script to backup to a "System Files" folder on my NAS:

#!/bin/bash  
sudo rsync -aAXv --progress --delete /etc /NAS/System\ Files/  
sudo rsync -aAXv --progress --delete /opt /NAS/System\ Files/  
sudo rsync -aAXv --progress --delete /root /NAS/System\ Files/  
sudo rsync -aAXv --progress --delete /snap /NAS/System\ Files/  
sudo rsync -aAXv --progress --delete /usr/local /NAS/System\ Files/usr/  
sudo rsync -aAXv --progress --delete /var /NAS/System\ Files/  

Once I work out the bugs, I intend to set up a cron job to schedule this.

After testing just the /etc line of this code, I noticed there are numerous permissions errors such as:

rsync: symlink "/NAS/System Files/etc/rc0.d/K01bluetooth" -> "../init.d/bluetooth" failed: Permission denied (13)

In this answer, the user states that "Backing them (some files in root) up would be meaningless or they might be even harmful."

Is there a safe way to accomplish this without any errors or without harming my system? Any help is greatly appreciated.


FYI, I am aware that I can create a disk image using a program like Clonezilla, but I would prefer to use a solution that doesn't have to be manually maintained. Also, not sure if Timeshift would do what I'm trying to do, but since I'm running ZFS on root, Timeshift gave me the "device not found" error, since ZFS is not currently supported (as of Timeshift 20.03).

I already have my applications, repos, and keys backing up to my home folder using Apt-Clone, and Duplicity set to backup my home folder to my NAS.

References:
How can I set up incremental backups to include my themes and customisation on Ubuntu 18.04?
How to backup settings and list of installed packages
What is the easiest NAS setup to back up an Ubuntu machine?

guttermonk
  • 1,024

1 Answers1

0

It took several days of work, but I was able to solve my problem by changing my back-up command and changing a setting on my NAS.

Here is my updated script, which I created a cron job for:

#!/bin/bash

sudo rsync -aAXvlH --delete --exclude={"/bin/","/boot/","/dev/","/home/","/lib/","/lib32/","/lib64/","/media/","/mnt/","/NAS/","/Pool-1tb/","/Pool-500gb/","/proc/","/run/","/sbin/","/srv/","/sys/","/tmp/","/usr/bin/","/usr/games/","/usr/include/","/usr/lib/","/usr/lib32/","/usr/libexec/","/usr/sbin/","/usr/share/","/usr/src/",".Trash"} / /NAS/System\ Files/

Here are the flags I used:

-a - Archive mode includes among other things, the options -o and -g, which preserves owners and groups. This requires that you run rsync as root.
-A - Preserve Access Control List.
-X - Preserve extended attributes.
-v - It will show the progress of the backup.
-l - Copy symlinks as symlinks.
-H - Preserve hard links.

To resolve the plethora of symlink errors I got when running rsync, on my Synology, I had to go to Control Panel / File Services / SMB / Advanced Settings and had to check the box next to "Allow symbolic links within shared folders".

If you found this helpful, please consider an up-vote. Thanks!

guttermonk
  • 1,024