This is an old revision of the document!


Rsync Backup

Rsync Backup is a group of bash scripts for Linux that utilise rsync to create a disk based incremental backup system.

Features

  • Runs from cron
  • Uses ssh to access remote hosts
  • Can support full host backup using setuid
  • One directory per backup host
  • One directory per backup operation utilising hard links to save disk space
  • Purge operation to remove old directories
  • Directory sticky bit utilised to disable purge operation
  • Purge operation may be disabled entirely

Install

Whether you install on a backup server or target host, fetch scripts from repository.

hg clone http://hg.kewl.org/pub/rsync-backup
Server

The server install will create a user called rsync, its home directory, a cron entry and place the scripts within a bin directory. The purge process is added to sudoers for the rsync user and the rsync binary is installed in the home directory setuid root.

The backup folder by default is /opt/fs/rsync and this is created, along with a log directory /var/log/rsync

The backup directory can be changed prior to install by editing the SYNCDIR variable in the file bin/config

sudo make install-server

ssh

ssh should be setup manually and the install process created a .ssh directory ready for this.

Changing to user rsync is best achieved like this:

sudo -s
/bin/su - rsync
Client

Full backup

For targets hosts, perform the client install. This creates the user rsync and copies the scripts into the home directory and creates a setuid root rsync binary and nothing more.

sudo make install-client

User backup

For user only backup on a target, the requirements are ssh access and rsync being available. If these two cases are met then when configuring the host, the login parameters and path to rsync must be set in the target config (see below).

ssh

The server ssh public key must be added to the authorized_keys file to access the client.

Configuration

An RSA ssh key with an empty passphrase must be generated and the public key added to each target's authorized_keys for user rsync when using the client installed above, or added to for the login user otherwise.

Variables

A file named config contains global variables for server operation.

Variable Usage Default
ETCDIR rsync host config /home/rsync/etc
SYNCDIR rsync backup directory /opt/fs/rsync
RSYNC local and remote rsync command /home/rsync/bin/rsync
PURGE directory purge command or empty sudo /home/rsync/bin/purge
Hosts

Each target host can have up to three server configuration files in ETCDIR.

In the following, “example” represents a hostname which is reachable with ssh.

example.conf

The .conf file contains target directories to be backed up.

/home/loginname

The .omit file contains target files or directories to be ignored during backup.

example.omit

/home/loginname/.history

example.sh

The .sh file is included prior to starting the backup process, this can contain one of two variables or anything else needed to be performed beforehand.

#! /bin/bash
SSH="ssh -2 -p 2222 -l loginname"
RSYNC_PATH="/bin/rsync"

In the above, SSH is used to set the login details for the connection and RSYNC_PATH set to the target rsync binary.

By default the backup process will login as user rsync and use the setuid binary found in the rsync home directory. This will allow a full host backup.

Variable Usage Default
SSH ssh command line ssh -2
RSYNC_PATH rsync command line /home/rsync/bin/rsync

When backing up the localhost, just use the hostname and rsync will copy files directly rather than use ssh.

Purge

After each backup operation a directory purge is performed to remove old directories. This can remove temporary data within a backup period and this should be appreciated.

Rules

The purge process applies the following rule to the host and backup directories:

  • Do not remove if the sticky bit is set

The purge process applies the following rules to backup directories:

  • Do not remove if less than 1 week old
  • Remove if not created on a Sunday
  • Do not remove if Sunday is the first Sunday of the month otherwise remove all Sundays older than 12 weeks
Disable

To disable the purge process, set the PURGE variable to “” in the config.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies