External Backup Script using Rclone
This script allows for an automatic backup of important information related to the configuration of your applications, excluding Plex. It can then be configured to store it or either Google drive or a local folder on your Ultra.cc service.
Initial Setup
- Create three new folders, one may already exist this is fine
mkdir ~/lock
mkdir ~/scripts
mkdir ~/rclone-backup
- Then you need to enter the new folder called scripts
cd ~/scripts
- And create the script file
nano rclone-backup.sh
- Paste the following lines into to editor:
#!/bin/bash
exec {lock_fd}>/home/username/lock/BackupLock || exit 1
flock -n "$lock_fd" || { echo "ERROR: flock() failed." >&2; exit 1; }
if [ -z "$STY" ]; then exec screen -dm -S rclone-backup /bin/bash "$0"; fi
DATE=$(date +%Y-%m-%d-%H%M%S)
tar --exclude="$HOME"/.config/plex --exclude="$HOME/.config/jellyfin" -czvf "$HOME"/rclone-backup/MyUltraBackup-$DATE.tar.gz "$HOME"/.apps "$HOME"/.config
rclone copy -v --bwlimit=5M /home/username/rclone-backup/ remotename:/MyUltraBackup
flock -u "$lock_fd"
- Make sure to replace
username
to your Ultra username. - Make sure to replace
remotename
to match your Rclone remote name. - You can execute
rclone listremotes
to see your configured Rclone remotes. - Save the script and exit the nano editor by pressing
Ctrl+X
thenY
thenENTER
.
Test Script
- First, navigate to the
~/scripts
folder.
cd ~/scripts
- Next, we need to make the script executable.
chmod +x rclone-backup.sh
- The script is now ready to be executed, which can be done with the following command.
./rclone-backup.sh
If the script is running and you were to rerun it, you may see an error message ERROR: flock() failed
. This is a file lock to stop multiple script executions running simultaneously. If you are sure the script is not in fact running, you can delete the lock file from the ~/lock
directory.
Check Progress
You can also check the progress of the backup script, which is running in a screen session.
- Attach to the screen session with the following command.
screen -rd rclone-backup
- To detach from the screen session and leave the script running in the background, press
ctrl+a
and then pressd
.
Automate Script
Once you have concluded the script to be running successfully, you can schedule it to be automatically executed via crontab.
- Open crontab with the following command:
crontab -e
- Inside the crontab add the following line at the bottom of the crontab file.
- Make sure to replace
ultra
with your Ultra username. - The script will run at midnight every 3 days, but can be reconfigured to your liking. See crontab.guru for more information.
0 0 */3 * * /home/ultra/scripts/rclone-backup.sh
- Save and exit crontab by pressing
Ctrl+X
thenY
andENTER
.
If you require further assistance, you can open a support ticket here!
Feedback and suggestions regarding this article are welcome on our Discord server