How to set adult automobile rsync backups regulating ssh

Linux has all a collection we need to emanate a simple, programmed network backup. Even better, it’s really easy to set up, and it will offer we though destroy (as prolonged as your network is adult and running) until we no longer have a need for this backup.

How do we make this sorcery happen? With ease, my friend. I’ll uncover we how.

SEE: Data Backup Policy

What you’ll need

First and foremost, you’re going to be doing this from and to Linux. It doesn’t matter what placement you’re using, so prolonged as it’s Linux. Both source and aim will need to have openssh-server installed. If we need to implement openssh-server on possibly machine, we can do this from a GUI package manager, or run a designation from a authority line.

For example, installing on Ubuntu would need a command:

sudo apt-get implement openssh-server

You will also need to beget an ssh key. This is important: We will be generating a passwordless ssh key. Yes, this could be deliberate a confidence issue, though we assume this is being used on a secure network; if your network (or your source and target) isn’t secure, we substantially shouldn’t be deliberation such an choice as passwordless backups. However, if we have a need for an programmed rysnc backup from one appurtenance to another, here’s how to do it.

Generate an ssh key

The initial step is to beget a passwordless ssh key. Follow these steps.

  1. Open a depot window.
  2. Issue a authority ssh-keygen -t rsa.
  3. When stirred for a storage location, strike Enter on your keyboard.
  4. When stirred for a password, strike Enter on your keyboard.
  5. When stirred to determine your password, strike Enter on your keyboard.

The above stairs will outcome in a era of an ssh keypair. If we demeanour in ~/.ssh

  • id_rsa
  • id_rsa.pub

Copying a pub key

We now have to duplicate a id_rsa.pub pivotal from a source to a target; this is managed with a assistance of ssh. Here’s what we do.

  1. Open a depot window.
  2. Issue a authority ssh-copy-id -i ~/.ssh/id_rsa.pub USERNAME@REMOTE_HOST_IPUSERNAMEREMOTE_HOST_IP
  3. When prompted, enter a cue for a remote host.

The ssh pivotal will automatically duplicate into a required plcae on a target, and you’re prepared to build a backup script.

The backup script

We’ll emanate a really elementary backup book for this process. I’m going to assume a source folder to backup is ~/TEST~/BACKUPS/—

#!/bin/sh
rsync -e ‘ssh -p 22’ -avzp /home/USER1/TEST REMOTE_HOST_IP:/home/USER2/BACKUPS

  • USER1
  • TEST
  • REMOTE_HOST_IP
  • USER2
  • BACKUPS

Save that record with a name rsync_scriptchmod +x rsync_script

Before we set adult a automation process, exam a book with a authority ./rsync_script

Automating a backup

We’ll use cron to automate a backup of a script. To make this impossibly easy, we can dump your rsync_script into one of a following directories:

  • /etc/cron.hourly
  • /etc/cron.daily
  • /etc/cron.weekly
  • /etc/cron.monthly

If we need a backup book run during a specific time, you’ll have to manually emanate a cron pursuit by arising a authority crontab -e

00 00 * * * /usr/local/rsync_script

The above crontab entrance assumes we changed a rsync_script into /usr/local/ and that we wish a book to run each day during midnight. Save a cron record (usually by attack [Ctrl]+[x]) and it will start regulating a subsequent time a time strikes midnight.

As elementary as it gets

This process of subsidy adult with rsync over ssh is impossibly simple; we can make it distant some-more difficult and even emanate scripts to run mixed backups over ssh.

Remember:

Also see

Article source: http://www.techrepublic.com/article/how-to-set-up-auto-rsync-backups-using-ssh/#ftag=RSS56d97e7

Related posts