Automated remote backup with rclone

Discussion in 'Tips/Tricks/Mods' started by HenrysCat, Mar 30, 2020.

  1. HenrysCat

    HenrysCat New Member

    After much searching I was unable to find a satisfactory solution to backup the /var/backup/ folder (which is where ISPConfig stores the backup files) to a remote server, so I came up with this to backup from VPS to my Synolgy nas drive located at home and thought I would share.

    First you need to install rclone https://rclone.org/downloads/ (I use debian 10)
    So login to a command line and enter
    Code:
    curl https://rclone.org/install.sh | sudo bash
    Once installed type 'rclone config'

    Type n, then give it a name in this example we are using the name sftpbackup

    (all steps below are seperated by commas)

    Select 29 for SSH/SFTP Connection (this seems to change with version updates but correct as of v1.51.0)
    add your host name/ip address for the SFTP server, user name, port number, Type 'y' for own password, enter password, press enter for default, type 'g' generate random pasword, 1024, yes (dont forget to save the password), press enter for default, press enter for default, press enter for default, 'n' to edit advanced config, type 'y' this is ok, type q to quit

    Next create a shell script, type
    Code:
    nano /usr/local/ispconfig/server/sftp-backup.sh
    copy/paste the below (this is for my Synology nas at home, you need to edit the /volume1/Backup/Backup part to suit your nas)
    Code:
        #!/bin/bash
    
        if pidof -o %PPID -x "sftp-backup.sh"; then
        exit 1
        fi
        rclone copy /var/backup/ sftpbackup:/Backup/Backup --sftp-path-override /volume1/Backup/Backup
        exit
    Type ctrl X, then y, then enter to save

    now make the file executable
    Code:
    chmod a+x /usr/local/ispconfig/server/sftp-backup.sh
    Now add a cron to run the script,
    Code:
    crontab -e
    add to the bottom
    Code:
    0 5 * * * /usr/local/ispconfig/server/sftp-backup.sh >/dev/null 2>&1
    This will run every day at 5am

    To test the script run
    Code:
    /usr/local/ispconfig/server/sftp-backup.sh
    This is not limited to nas drives, rclone supports many different backup solutions, just use the above and adapt as necessary.
    Hope this helps someone, any questions just ask.
     
    Last edited: Mar 31, 2020
    till likes this.

Share This Page