Shell script to rsync backup files to a remote server

VitalPBX Community Support General Discussion Shell script to rsync backup files to a remote server

Up
0
Down
  • Post
    kbohannon
    Participant

    I am still new to Linux and the CLI. Until backup via FTP becomes an option, does anyone have any quick and dirty tutorial on writing a shell script and cron job to rsync the contents of /var/lib/ombutel/static/backups/c4cablahblahblah/* to a remote server? I already have a server set up with SSH via cert.

    I am trying this method instead of my particular VPS provider’s backup method because the restoration from backup images has not worked, and I have now 20+ VPBX servers to be backed up.

    0
Viewing 6 replies - 1 through 6 (of 6 total)
  • Replies

    You may use the SCP command, first, you may create a shell script named “backup.sh”  under “/var/lib/ombutel/scripts” with the following content

    #!/bin/bash
    set -e

    scp -r /var/lib/ombutel/static/backups/c4cablahblahblah remote_username@10.10.0.2:/remote/directory

    After create the script you must give it execution permissions:

    chmod +x backup.sh

    Now, go to “/etc/cron.d” and create a file named “external-backup” with the following content:

    0 0 * * 0 root /var/lib/ombutel/scripts/backup.sh

    Save the file and restart the crond service

    systemctl restart crond.service

    With all these steps you will be able to copy backups to an external server every day at midnight

    0
    kbohannon
    Participant

    Working! And with an SSL key and not a password. This calls for milk and cookies…

    0

    It is the same command, but you must add the flag “i” plus your SSH public key

    scp -i ~/.ssh/id_rsa.pub -r /var/lib/ombutel/static/backups/c4cablahblahblah remote_username@10.10.0.2:/remote/directory
    0
    kbohannon
    Participant

    For those who might be interested, until we have a GUI option, this is my script to take the nightly backup and drop it onto a remote directory named using the hostname (I have many servers to backup):

    scp -i~/.ssh/backupserver /var/lib/ombutel/static/backup/c4ca4238a0b923820dcc509a6f75849b/* amicusvoice@[backupserver]:~/Backups/$(hostname)

    I have about 30 servers to backup (fun). Next step is figuring out how to rsync over SSH so my backup server doesn’t fill up every six months.

    Thanks for the help Mr R!

    0
    deanwalker
    Participant
    GB

    How far are we away from FTP backups via gui?

    Thanks

    0
    mo10
    Participant

    deanwalker:

    How far are we away from FTP backups via gui?

    Thanks

    +1

    0
Viewing 6 replies - 1 through 6 (of 6 total)

Tagged: ,

  • You must be logged in to reply to this topic.