Automatic config/saves backups (nightly rclone)

Community created YouTube tutorials, interviews and helpful online information guides.
User avatar
Natrox
Scripting Wizard
Posts: 36
Joined: Thu Aug 04, 2022 2:05 pm
Has thanked: 8 times
Been thanked: 73 times

Automatic config/saves backups (nightly rclone)

Unread post by Natrox »

Hello!

This is a small guide on how to set up automatic backups for configs, saves and savestates.
It's not a lot of work but you need to do some extra work to set it up.

Before you proceed, here are the requirements:

  • SSH access.
  • Rclone configured and working (/media/fat/Scripts/rclone.conf).
  • Consistent internet connection.
  • MiSTer powered on at all times.

If all requirements are met, let's get to work!

First, open up an SSH shell. You can use PuTTY or WSL to connect.
Once connected, type cd /media/fat/Scripts and then ls and check for the following scripts:

  • rclone_config_upload.sh
  • rclone_saves_upload.sh
  • rclone_savestates_upload.sh
    Of course, if rclone is working, you should have these scripts already.

Next, type cd /media/fat/linux. You will need to create a new folder, using:

Code: Select all

mkdir crons

You should now have a folder named /media/fat/linux/crons.

Now, open up user-startup.sh with nano user-startup.sh.
At the end of the file, add the following line:

Code: Select all

crond -c /media/fat/linux/crons

Press CTRL+X and answer Y to the question.

Finally, you will need to create a "crontab". This is basically a list of time points and commands to run.
To edit the crontab, use the following command:

Code: Select all

EDITOR=nano crontab -e -c /media/fat/linux/crons

You will be presented with an empty file, add the following text to it:

Code: Select all

0 0 * * *       /media/fat/Scripts/rclone_config_upload.sh > /media/fat/auto_upload.log
0 0 * * *       /media/fat/Scripts/rclone_saves_upload.sh >> /media/fat/auto_upload.log
0 0 * * *       /media/fat/Scripts/rclone_savestates_upload.sh >> /media/fat/auto_upload.log

This instructs the scheduling utility (crond) to run the upload scripts at midnight daily.
One again, save your work and exit the editor. You're all done! Reboot to apply changes.

More info:

The two zeroes on each line refer to minute and hour respectively. Hour is in 24-hr format.
As specified, this command runs at minute 0 hour 0 - aka midnight. You can change the scheduling of course, some examples:

Code: Select all

# Order is:
*/5 * * * * # Every 5 minutes
0 * * * *   # Every hour
0 0 * * 0   # Every Sunday at midnight

You can run whatever command or script you want, as long as you specify the full path. You could even automate updates like so:

Code: Select all

# I do not recommend this, unless you are sure that you are not using the MiSTer while this command is executed.
# The '>' is for logging.
0 * * * *	/media/fat/Scripts/update_all.sh > /media/fat/update_all.log

The syntax of crontab is like this (* is "any"):

uBmZl1l.png
uBmZl1l.png (3.68 KiB) Viewed 2297 times

I hope you have found this guide useful!

Post Reply