Difference between revisions of "Rsnapshot"

From Notes_Wiki
m
m
Line 58: Line 58:
</pre>
</pre>


==ssh options==
To supply a different set of options for SSH such as -p for changing port use:
<pre>
backup          root@commonhosting-cwp.sbarjatiya.com:/etc/    commonhosting-cwp.sbarjatiya.com/      +ssh_args=-p 36548
</pre>
There are also '<tt>rsync_short_args</tt>' and '<tt>rsync_long_args</tt>'. 
ssh has no args passed by default. 
rsync has following arguments by default
;short_args  : -a
;long_args : --delete --numeric-ids --relative --delete-excluded





Revision as of 11:44, 15 May 2022

<yambe:breadcrumb self="Rsnapshot">Backup tools|Backup tools</yambe:breadcrumb>

CentOS 7.x rsnapshot has updated notes on rsnapshot

Installation

rsnapshot can be installed using yum when extras, rpmfusion, rpmforge etc. repositories are also configured properly.


Configuration

rsnapshot uses '/etc/rsnapshot.conf' file for configuration. Two very important points about configuration file are:

  • All paths must end with / and all backup destination should be relative
  • Various fields in file are separated using Tab. Space does not separates fields
    If differentiating between space and tab in editor is an issue, try to use gedit with plugin "Draw spaces" enabled.


Recommended configuration

Following configuration is recommended for Cent-OS / Linux users:

  • Configure 'snapshot_root' as absolute path on current system. Note that in case of remote backups rnapshot is always run on backup server and not on client to be backuped up.
  • Leave cmd_cp, cmd_rm, cmd_rsync, as it is
  • Uncomment cmd_ssh
  • Set proper backup intervals. The order of interval lines is important. More frequent backup lines should come first. Example configuration is
    retain hourly 6
    retain daily 7
    retain weekly 4
    retain monthly 3
    Older versions of rsnapshot used keyword interval instead of retain. If you are working with considerably older version perhaps you need to use 'interval hourly 6' etc. appropriately.
  • Decrease loglevel to 2
  • Enable link_dest by setting its value to 1
  • Setup local backups such as
backup_script	/bin/date "+ backup of officepc started at %c" > start.txt		officepc/officepc_start/
backup		/etc/			officepc/
backup		/home/			officepc/
backup		/root/			officepc/
backup		/documents/		officepc/
backup		/mnt/data1/ebooks/	officepc/
backup		/mnt/data1/songs/	officepc/
backup		/mnt/data1/personal/	officepc/
backup_script	/bin/date "+ backup of officepc completed at %c" > end.txt		officepc/officepc_end/
  • Setup remote backups, such as
backup_script	/bin/date "+ backup of officepc started at %c" > start.txt	officepc/officepc_start/
backup		root@10.5.1.222:/documents/		officepc/	+rsync_long_args=--bwlimit=1000
backup		root@10.5.1.222:/etc/			officepc/	+rsync_long_args=--bwlimit=1000
backup		root@10.5.1.222:/home/			officepc/	+rsync_long_args=--bwlimit=1000	
backup		root@10.5.1.222:/root/			officepc/	+rsync_long_args=--bwlimit=1000	
backup		root@10.5.1.222:/mnt/data1/ebooks/	officepc/	+rsync_long_args=--bwlimit=1000
backup		root@10.5.1.222:/mnt/data1/songs/	officepc/	+rsync_long_args=--bwlimit=1000
backup		root@10.5.1.222:/mnt/data1/personal/	officepc/	+rsync_long_args=--bwlimit=1000
backup_script	/bin/date "+ backup of officepc completed at %c" > end.txt	officepc/officepc_end/

ssh options

To supply a different set of options for SSH such as -p for changing port use:

backup          root@commonhosting-cwp.sbarjatiya.com:/etc/     commonhosting-cwp.sbarjatiya.com/       +ssh_args=-p 36548

There are also 'rsync_short_args' and 'rsync_long_args'. ssh has no args passed by default. rsync has following arguments by default

short_args
-a
long_args
--delete --numeric-ids --relative --delete-excluded


Database dump configuration

Example configuration that dumps mysql databases during backup is

backup_script	/usr/bin/sshpass -p <password> mysqldump -u root -p wikidb_notes | bzip2  > /documents/room-documents/documents/databases/mysql/notes_wiki/wikidb_notes.sql.bz2		officepc/.ignore1/
backup_script	/usr/bin/sshpass -p <password> mysqldump -u root -p wikidb_res | bzip2  > /documents/room-documents/documents/databases/mysql/research_wiki/wikidb_res.sql.bz2		officepc/.ignore2/
backup_script	/usr/bin/sshpass -p <password> mysqldump -u root -p wikidb_readme | bzip2  > /documents/room-documents/documents/databases/mysql/readme_wiki/wikidb_readme.sql.bz2		officepc/.ignore3/

Note that in this case rsnapshot.conf file should be readable only by root user.


In case database is not located on same machine as rsnapshot machine then use following steps:

  1. On remote server create /opt/take-database-dump.sh with command to put database dump in one of the folders which will be backed up by rsnapshot backup directive. Example shell-script for obtaining mysql dump can be like:
    /<path>/mysqldump -u bitnami -p<password> bitnami_redmine | bzip2 > /opt/bitnami_redmine.sql.bz2
  2. On rsnapshot server configuration for corresponding server have following to run the database dump script during backup
    backup_script /usr/bin/ssh root@<server-fqdn> /opt/take-database-backup.sh >/dev/null 2>&1 <server>/.ignore2/
  3. Ensure that folder where database script is taking database dump, is backed up by rsnapshot after database dump script is executed. (Eg /opt/) in above example.


Important points

  • In backup_script parameters to commands are separated by space which is not a problem as rsnapshot only uses tab as field separator. Hence we can give script commands which require arguments without any problem
  • Backup specific options can be specified in optional fourth field in backup. '+' in such cases indicates keep existing options and add these additional options with them. Without '+' original options will be removed and given options will be the only options
  • Final folder used as target of backup_script should be unique. Hence following is not acceptable
backup_script     echo "hello" > hello.txt     pc1/folder1/
backup_script     echo "hi"  > hi.txt          pc2/folder1/

as both destinations end with folder1, even though parent folder is different. This is most likely bug and may get corrected in future.

  • Backup script is run in temp folder and contents of temp folder are then synced with specified destination folder
  • We can run commands which require password like mysql_dump with ssh-pass.
  • Commands can be run remotely using backup_script as '/usr/bin/ssh root@10.5.1.222 "ls > /root/ls.txt"' with destination folder ignore1 or similar. Then contents of /root can be backed up to get contents of ls.txt. This when used in combination with sshpass can allow backup_script to take database dumps in specific folders, before those folders are backed up.


Crontab configuration

One can configure crontab using 'crontab -e' command to take backups at specified intervals automatically. Sample crontab configuration is

0 0,4,8,12,16,20 * * *       /usr/bin/rsnapshot hourly
45 23 * * *       /usr/bin/rsnapshot daily
30 23 * * 0       /usr/bin/rsnapshot weekly
15 23 1 * *       /usr/bin/rsnapshot monthly




Other options

We can use 'rsnapshot du' or 'rsnapshot du <folder_name>' to get information about space occupied by particular folder



Restoration

Root user can restore files or directory structures using cp or rsync. To allow normal users to restore their files (and only their files) we can use following steps:

  1. Create a parent folder accessible only by root using something like
    mkdir /private
    chmod 700 /private
  2. Make snapshot folder for users readable by everyone using
    mkdir /private/snapshots
    chmod 755 /private/snapshots
  3. Then share snapshot folder using NFS as explained in Configuring basic NFSv3 server
  4. Then mount exported NFS partitions in some folder on system from where users can access only their own backups and not backups of other users


Steps learned from official rsnapshot how to at time of writing at http://rsnapshot.org/howto/1.2/rsnapshot-HOWTO.en.html#configuration


<yambe:breadcrumb self="Rsnapshot">Backup tools|Backup tools</yambe:breadcrumb>