Last active
July 25, 2023 05:14
-
-
Save earlvanze/312043b33e1d69e6380ce533be8d77ab to your computer and use it in GitHub Desktop.
Bash script for backing up to Google Drive using rclone with "nice" on a Synology DiskStation NAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Here's my bash script using "nice" for CPU prioritization on a Synology DiskStation NAS: | |
#!/bin/bash | |
echo "Backing up server folder to Google Drive." | |
#echo | |
# run rclone using nice, with config options | |
# >> appends to log file | |
# 2>&1 silences all output | |
# & runs in background | |
/bin/nice rclone -u --config="/var/services/homes/[user]/.rclone.conf" sync /volume1/[volume] [Google username]://[folder] >> /volume1/homes/[user]/gdrivebackuplog.txt 2>&1 & | |
#echo | |
# Info on rclone - rsync for cloud storage: http://rclone.org/docs/ | |
# Info on nice: https://en.wikipedia.org/wiki/Nice_(Unix) | |
# http://superuser.com/questions/537509/nice-commands-in-a-sh-script-for-cron-jobs | |
# Synology Task Scheduler tutorial: https://www.domoticz.com/forum/viewtopic.php?t=9921 | |
#echo "All done!" | |
#echo "Press any key to exit." | |
#read -n 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have configured third-party software to be able to install additional tools that are not normally
available on the Synology platform. These tools are:
ipkg - third-party software manager, similar to apt-get. To install, follow the instructions at
http://howden.net.au/thowden/2014/10/synology-installation-of-ipkg-dsm-yum-or-apt-get-equivalent/
Specifically, the text in
code
should be copied and pasted into a Terminal prompt connected via SSH. To connect to SSH, ensure SSH is enabled in DSM’s Control Panel > Advanced Mode > Terminal & SNMP > Enable SSH service. If on Windows, you will need to install PuTTY. If on Mac or Linux, simply open the Terminal app, which is built in. In Terminal, connect via SSH:ssh [email protected]
When prompted for a password, type in the password for the user.
Download ipkg for Synology server with Intel Atom CPU:
wget http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/syno-i686-bootstrap_1.2-7_i686.xsh
then run it with
sh http://ipkg.nslu2-linux.org/feeds/optware/syno-i686/cross/unstable/syno-i686-bootstrap_1.2-7_i686.xsh
This installs ipkg, but it is not in the path for the Synology system. To add it to the path:
check the path
cat /etc/profile
and this should be there
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin export PATH
extend the path to include our /opt directories with two command lines
Then we can test that ipkg is installed and will run from anywhere with
ipkg -v
Should respond with something like
ipkg version 0.99.163
If you now try to install a package, you will get an error
Which is ok, this is expected because the new install does not yet know where to look for nano
Note: nano is just a favourite package of mine, (nano text editor)
The final step for installing ipkg is to update the repositories
ipkg update
Then try again and as ipkg now has a repository to call on, it should find the install package and install it.
Install nano text editor and unzipping tool:
sudo ipkg install nano unzip
Download rclone - Google Drive and cloud storage rsync tool:
sudo wget http://downloads.rclone.org/rclone-current-linux-386.zip
Unzip folder:
sudo unzip rclone-current-linux-386.zip
Change directory into rclone:
cd rclone-current-linux-386
Copy binary file from rclone folder to system folder and change owner and permissions:
Configure rclone with Google Drive account and Client ID and Secret from developers.google.com - May not be necessary if hidden .config folder exists, run to check if account is already configured:
rclone config
Install procps which includes nice utility to limit CPU usage by priority. htop lists processes
running (like top does) but with nice preferences as well:
ipkg install procps htop
Created rclone-google-drive.sh script to automate running rclone with nice - outputs to gdrivebackuplog.txt file. No reconfiguration needed, just make sure this is in the /volume1/homes/user/ (aka ~ aka home) folder. Both nice and rclone need to been installed for the script to run properly.
Run the script to run the backup manually:
./rclone-google-drive.sh
Check the status of the backup:
cat gdrivebackuplog.txt
Used Task Scheduler tool on Synology DSM 6.0 web management (216.165.112.160:5000) to run script daily at 2 AM. No reconfiguration needed if DSM system configuration backed up.