Skip to content

justcoding-dev/qnap_scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QNAP Scripts

This is my backup script to backup my important shares from my QNAP NAS to an external harddrive or to another NAS.

Prerequisites

The rsync version that QNAP ships with its OS is rather old, so it's best to first install entware (https://github.com/Entware/entware/wiki/Install-on-QNAP-NAS) on the QNAP and then install a recent rsync version:

opkg install rsync

Usage

Just run the script to see the usage information:

.../qback.sh

To make a backup, first setup a .config folder on your backup drive. Checkout the usage information and the files in the config.example folder and create your own shares file in the .config folder.

For example, if your backup drive is mounted as /share/MyPersonalBackup:

cp -r /path/to/this/repo/config.example /share/MyPersonalBackup/.config
nano /share/MyPersonalBackup/.config/shares

Then run the script in superdry mode to get a feeling of what it will do:

./qback.sh -dd /share/MyPersonalBackup

If you are satisfied with the output (some experience with rsync helps, or you can paste the logged rsync command to https://explainshell.com), you can try the normal dry run:

./qback.sh -d /share/MyPersonalBackup

This will create the needed directories on the backup drive and run rsync in dryrun mode, so you can see what will be copied. Don't worry though, it's all fake and nothing is being written yet.

Finally, to make your backup, run

./qback.sh /share/MyPersonalBackup

The backup will be written to the folder store/__cur on the backup drive. If all rsync commands executed successfully, this temporary folder will be renamed to a timestamped folder with the date of when the script was run. If the script is stopped and restarted, it will continue updating the temporary folder, so there should be not incomplete backups hanging around.

Since the script checks if it's already running, it should be possible to run it regularly from a cron job - I have not really tested that though, so please save the logs and check them regularly.

Pull backup from a remote device

If you plan to pull a backup of your QNAP shares from a remote machine, you need to be able to ssh into the NAS, ideally using ssh key so you don't have to enter the passwort. Unfortunately the admin users home directory is regenerated at each reboot, so it cannot store the public key of the remote user.

So you need to create a new local user on the QNAP and give it the right to sudo rsync. If your backup user is called 'RemoteBackup', create the file /usr/etc/sudoers.d/RemoteBackup.user with the following content:

RemoteBackup ALL=(ALL) NOPASSWD: /opt/bin/rsync

By the way, this file will be removed at reboot as well (eff you, QNAP!), so you need to make sure it is in place before the backup starts.

Pull backup from another QNAP NAS

If you run your backup on one QNAP NAS to create a backup from another QNAP, you also need a place to store the private ssh key. Again, the admin account is not suitable because of the reboot cleanup.

So, again, setup a 'backup' user and give it the right to sudo ssh in /usr/etc/sudoers.d/backup.user:

RemoteBackup ALL=(ALL) NOPASSWD: /opt/bin/ssh

and add the --ssh parameter to the backup call:

.../qback.sh --ssh="/usr/bin/sudo -u backup /opt/bin/ssh"

to run the ssh command as the backup user.

About

Scripts for my QNAP NAS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages