Linux backups on a Synology NAS

The Synology NAS products work well for backing up or sharing media files and documents in an informal home environment. However, a Synology NAS is not well suited as a general backup device for a Linux computer.

The problems below can be overcome by archving your Linux files with tar or an equivalent archive manager, then copying the tarballs to the Synology NAS. But that can be inconvenient. You might be tempted to use the Synology NAS as an extension drive and simply copy files to the NAS for backup. However, therein lies four gotchas for the Linux user which we’ll discuss below:

  • File permissions

  • File ownership

  • Case insensitive filesystem

  • Symlinks

File permissions

Suppose we start with a sensitive file on the Linux computer with permissions set so that only the owner can access the file:

-rw------- 1 dm dm 4 Apr 20 11:06 junk

Suppose we use rsync -a to copy the file to the NAS and then copy it back like this:

rsync -av ./junk dm@ rsync -av dm@ .

The permissions are retained, great. But if we mount the NAS drive on our Linux computer with Samba, the permissions allow anyone to read it:

-r--r--r-- 1 dm dm 1740013 Apr 20 10:59 junk

To preserve sensitive file permissions when backing up and restoring files, you must copy and restore the files using rsync -a directly to and from the NAS and never allow anyone else to mount the NAS filesystem.

File ownership

Suppose your Linux computer has a file owned by user dm and group www-data:

-rw-rw-r-- 1 dm www-data 0 Apr 20 11:14 junk

Let’s use rsync -a to copy it to the NAS and back:

rsync -av ./junk dm@ rsync -av dm@ .

Now its group ownership on the Linux computer has been lost:

-rw-rw-r-- 1 dm dm 0 Apr 20 11:14 junk

And if we look at the file by mounting the NAS directory on our Linux computer, the write permissions for group has been lost:

-rw-r--r-- 1 dm dm 0 Apr 20 11:23 junk

To backup and restore ownership and permissions for group and other, such as for files used by a web server, archive the files with tar or an other archive manager that preserves ownership and permissions.

Backing up your files in tarballs means that you cannot use the NAS’s Btrfs filesystem to make snapshots of backups. You can make incremental tarball backups, but restoring them means having to restore multiple tar files on top of each other.

Case insensitive filesystem

On a Linux filesystem, filename case is significant. For example, you could distinguish between a full-size image and a thumbnail by naming them with upper and lower case:

dm@linuxbox:/tmp$ ls -l junkdir -rw-rw-r-- 1 dm dm 335160 Apr 20 11:34 junk.jpg -rw-rw-r-- 1 dm dm 7654088 Apr 20 11:34 junk.JPG

In many Linux distributions, some directories contain variations of filenames that differ only in upper or lower case.

If we use rsync -a to copy such files to the NAS, the filename casing is preserved and all the files are copied. But let’s use rsync -a to copy our two test files to a NAS directory mounted on our Linux computer:

dm@linuxbox:/tmp$ rsync -av ./junkdir/ /home/dm/mnt/nasdir/junkdir/

Now only one file got copied, with the name of one of the files and the contents of the other file:

dm@linuxbox:~/mnt/nasdir$ ls -l ~/mnt/nasdir/junkdir/ -rw-r--r-- 1 dm dm 335160 Apr 20 11:34 junk.JPG

Rsync to a mounted NAS drive is case insensitive, so the first file got copied, then the second file that was copied overwrote the first file but the filename was unchanged.

To avoid losing files that differ in name casing, rsync directly to and from the NAS and not through a mounted NAS directory.

Symbolic links cannot be copied from a Linux computer to the Synology NAS. The Linux operating system and many applications use symlinks and will no longer fully function if backed up to a Synology NAS and then restored without the symlinks.

To backup and restore operating system files and applications, use tar or another archive manager that preserves symlinks.

Leave a comment

Your email address will not be published. Required fields are marked *