Guide: Automating Backups on Startos (requires SSH)

Please provide me feedback if you have any improvements, corrections, etc… The approach works with 0.4.0 and 0.3.5.1. PDF w/screenshots from 0.3.5.1 can be reached via a TOR browser at: https://nnpyen2cnj3qrafh3o2atfb7epi74ngmf7v3lkku6calsbibzegninqd.onion/api/public/dl/Qtn4B7z_?inline=true

Part 1: Make sure backups are configured and working through the graphical user interface.
1.1) Open your browser and access your Start OS server. Go to System Backups Create Backup.

1.2) Make sure you have a target location for your backups to be stored. You should also test the backups manually through the graphical user interface.

Part 2: SSH into your StartOS server and put it into a State to persist changes.
2.1) After you have SSH’d into your StartOS server, you should see a welcome message and a command prompt. My screenshots redact the exact host name of my server.

2.2) Enter the command below to put your StartOS server into a state to persist changes. If this is not done, then your changes will last only until the next restart of your server, at which point they will be overwritten.

sudo /usr/lib/startos/scripts/chroot-and-upgrade

Part 3: Determine the backup target identifier you wish to use.
3.1) To find the available backup targets, enter the command below.

start-cli backup target list

3.2) You will get a list of all of the available backup targets and their details. Select the one that you want based upon what you tested and confirmed in the GUI initial back up test at the start of this guide. The very first line for that back up target that you want will provide you the target ID. In my case it was cifs-6. My screenshots redact the exact host name of my server and the user name.

Part 4: Add an entry to the Root Level crontab for your StartOS server.
4.1) Enter the command below to edit your root crontab.

crontab -e

4.2) If this is your first time editing crontab on this server, it will prompt you with an option of which editor to use. Select option one, which is the nano editor.
4.3) After selecting that, it will bring you to an editor where you can modify the crontab entries. Any line that starts with a # is a comment and is ignored. The first time you open up crontab, it will be all comments and no scheduled commands. You can do your own research on scheduling using crontab to select the schedule that you want. Here we will only add one line with a command to create a backup and send the output to a text file. This will execute on the first day of every month at 5:30am. You will need to modify the command below for your target (mine was cifs-6) and for your StartOS server password (Pswd is not a good password):

30 5 1 * * start-cli backup create cifs-6 ‘Pswd’ >> /root/CronBackup.txt 2>&1

4.4) After adding that line in the editor, your screen should look something like this:

4.5) When you are done editing, you use Ctrl+X to exit. And then Y to save your work or N if you wish to not save your work. After you say yes to save your work, it will show you the file name to write. Just hit enter to accept the default. If you want to list the contents of crontab without editing. You may use this command:

crontab -l

4.6) You should see something that looks like this:

Part 5. Exit from make persistent mode.
5.1) To exit from make Persistent Mode, just enter the command below:

exit

5.2) Your server will restart, and after it restarts, your cron job will be active.

4 Likes

Thank you for this!

FYI: if you want to limit the backup to specific services, you can use something like this:

start-cli backup create cifs-6 ‘Pswd’ --package-ids bitcoind,electrs,mempool >> /root/CronBackup.txt 2>&1

You can get the package ids from the URL in the web UI when you click on a specific service.

Heads up for anyone doing this on 0.4.0-beta.9 — a couple of things have changed since the original guide:

  1. You have to log in to start-cli first now. On beta.9, start-cli backup target list just throws Unauthorized:
    UNAUTHORIZED until you authenticate. Once you’re in the chroot, run start-cli auth login (it’ll ask for your master password) before anything else.
  2. The target ID isn’t always cifs-x. That’s for a network share. If you’re backing up to a local USB or SSD it’ll be something like disk-/dev/sda1. Just run start-cli backup target list and use whatever key it spits back.
  3. Don’t put your password straight in the crontab. Drop it in a root-only file instead and read it at runtime:
    install -m 600 /dev/null /root/.backuppw
    printf ‘%s’ ‘YOUR_PASSWORD’ > /root/.backuppw
  4. Then the cron line becomes:
    30 5 * * * start-cli backup create “disk-/dev/sda1” “$(cat /root/.backuppw)” >> /root/CronBackup.txt 2>&1
  5. That keeps the password out of crontab -l and your logs. It does still show up in ps for the few seconds the job runs, but at least it’s not just sitting there in the crontab.

The backup create syntax is the same as before — start-cli backup create, all packages by
default, and --package-ids a,b still works if you only want specific services. Ran through this on two beta.9 boxes and everything backed up fine.

Great addition!!! Thanks for adding this. Start9 is updating the way backups work right now (should be in beta 10). After beta 10 is released, I will review my original guide and update it - and will certainly include your suggestions too!!!

1 Like