20. Backup

It is necessary to do regular backup to have a reliable system, even if you are using raid.

Backup your configs

Whether you need to save a backup of user accounts or the server configuration, you should use Calculate 2. To do so, please enter:

cl-backup

You can setup daily backup by creating a file in the /etc/cron.daily/ directory, containing the following:

#!/bin/bash
cl-backup

Do not forget to make this file executable.

Backup your data

Let us see an example: the server is using three hard drives for storage, mounted as follows:

#cat /etc/fstab
...
/dev/sda5       /var/calculate  xfs        noatime 0 0
/dev/sdb1       /var/calculate/server-data xfs noatime 0 0
/dev/sdc1       /var/calculate/server-data/samba/share xfs noatime 0 0
...

We backup to another server, which serves as a repository. The backup server's hard drives must be at least as big, and there must be at least three of them, as well. Data will thus be copied from each drive separately.

Most of the time the backup server is turned off and switched on only when copying data. To configure the wake function of the server, use the following description.

Here is an example of script used to synchronize users' data with the backup server:

#!/bin/bash

#backup server
BACKUP_IP=192.168.0.250
BACKUP_MAC=01:14:7b:10:3a:6a

#wake up the backup server
wol $BACKUP_MAC

#wait 5 minutes until it awakes
sleep 300

#synchronize from three partitions
rsync -e ssh --progress -aAzuhvSx --compress-level=9 --delete-after /var/calculate/ root@$BACKUP_IP:/mnt/backup1
rsync -e ssh --progress -aAzuhvSx --compress-level=9 --delete-after /var/calculate/server-data/ root@$BACKUP_IP:/mnt/backup2
rsync -e ssh --progress -aAzuhvSx --compress-level=9 --delete-after /var/calculate/server-data/samba/share/ root@$BACKUP_IP:/mnt/backup3

#turn off the server
ssh -o 'StrictHostKeyChecking=no' root@$BACKUP_IP halt

In this example, three partitions, namely /var/calculate, /var/calculate/server-data and /var/calculate/server-data/samba/share with the "x" option, which allows not to cross filesystem boundaries while copying.

Summary of most popular rsync options:
  • a - archive mode; equals -rlptgoD (no -H,-A,-X)
  • A - preserve ACLs (implies -p)
  • e - specify the remote shell to use
  • progress — show progress during transfer
  • l - copy symlinks as symlinks
  • z - compress file data during the transfer
  • u - skip files that are newer on the receiver
  • o - preserve owner (superuser only)
  • g - preserve group
  • t - preserve modification times
  • h - output numbers in a human-readable format
  • v - increase verbosity
  • p - preserve permissions
  • r - recurse into directories
  • S - handle sparse files efficiently
  • x - do not cross filesystem boundaries
  • n - perform a trial run with no changes made
  • compress-level — explicitly set compression level
  • delete-after — receiver deletes after transfer, not before.

Public key

In this example, files are transferred through ssh; therefore, before each transfer you will be prompted for the root password. You can create a public key and copy it onto the backup server to avoid it.

To do this, create a rsa key on your server by typing:

ssh-keygen

Copy this key into the root home directory on the backup server:

ssh-copy-id -i /root/.ssh/id_rsa.pub BACKUP_IP

Debug

Before running the script at the working system, try it in debug mode. To do so, use "-n": thus, rsync will not copy and delete files, but show the work progress.

Exclude files

Rsync can both exclude and include files by a given pattern. For example, "-exclude *. run" will exclude all files with the run extension.

Thank you!