Difference between revisions of "Rsnapshot"
(Created page with "=Installation= rsnapshot can be installed using yum when extras, rpmfusion, rpmforge etc. repositories are also configured properly. =Configuration= rsnapshot uses '<tt>/...") |
m |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Backup tools]] > [[Rsnapshot]] | |||
'''[[CentOS 7.x rsnapshot]] has updated notes on rsnapshot''' | |||
=Installation= | =Installation= | ||
Line 10: | Line 14: | ||
*'''All paths must end with / and all backup destination should be relative''' | *'''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''' | *'''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. | |||
Line 19: | Line 24: | ||
*Uncomment cmd_ssh | *Uncomment cmd_ssh | ||
*Set proper backup intervals. '''The order of interval lines is important. More frequent backup lines should come first'''. Example configuration is | *Set proper backup intervals. '''The order of interval lines is important. More frequent backup lines should come first'''. Example configuration is | ||
<pre> | *:<pre> | ||
*::retain hourly 6 | |||
*::retain daily 7 | |||
*::retain weekly 4 | |||
*::retain monthly 3 | |||
</pre> | *:</pre> | ||
*: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 | *Decrease loglevel to 2 | ||
*Enable link_dest by setting its value to 1 | *Enable link_dest by setting its value to 1 | ||
Line 49: | Line 55: | ||
backup root@10.5.1.222:/mnt/data1/songs/ 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 root@10.5.1.222:/mnt/data1/personal/ officepc/ +rsync_long_args=--bwlimit=1000 | ||
backup_script /bin/date "+ backup of officepc completed at %c" > | backup_script /bin/date "+ backup of officepc completed at %c" > end.txt officepc/officepc_end/ | ||
</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 | |||
Line 63: | Line 79: | ||
</pre> | </pre> | ||
Note that in this case rsnapshot.conf file should be readable only by root user. | 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: | |||
# On remote server create <tt>/opt/take-database-dump.sh</tt> 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: | |||
#:<pre> | |||
#:: /<path>/mysqldump -u bitnami -p<password> bitnami_redmine | bzip2 > /opt/bitnami_redmine.sql.bz2 | |||
#:</pre> | |||
# On rsnapshot server configuration for corresponding server have following to run the database dump script during backup | |||
#:<pre> | |||
#:: backup_script /usr/bin/ssh root@<server-fqdn> /opt/take-database-backup.sh >/dev/null 2>&1 <server>/.ignore2/ | |||
#:</pre> | |||
# 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. | |||
Line 78: | Line 106: | ||
*Backup script is run in temp folder and contents of temp folder are then synced with specified destination folder | *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. | *We can run commands which require password like mysql_dump with ssh-pass. | ||
*Commands can be run remotely using backup_script as '<tt>ssh root@10.5.1.222 "ls > /root/ls.txt"</tt>' 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. | *Commands can be run remotely using backup_script as '<tt>/usr/bin/ssh root@10.5.1.222 "ls > /root/ls.txt"</tt>' 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. | ||
Line 86: | Line 114: | ||
One can configure crontab using '<tt>crontab -e</tt>' command to take backups at specified intervals automatically. Sample crontab configuration is | One can configure crontab using '<tt>crontab -e</tt>' command to take backups at specified intervals automatically. Sample crontab configuration is | ||
<pre> | <pre> | ||
0 | 0 0,4,8,12,16,20 * * * /usr/bin/rsnapshot hourly | ||
45 23 * * * /usr/bin/rsnapshot daily | 45 23 * * * /usr/bin/rsnapshot daily | ||
30 23 * * 0 /usr/bin/rsnapshot weekly | 30 23 * * 0 /usr/bin/rsnapshot weekly | ||
Line 99: | Line 127: | ||
=Other options= | =Other options= | ||
==Delta space usage between backup copies== | |||
We can use '<tt>rsnapshot du</tt>' or '<tt>rsnapshot du <folder_name></tt>' to get information about space occupied by particular folder. In this case the latest backup is shown to occupy full space, but for other older folders only the diff space is mentioned. This is useful to see both total single backup space required and also typically incremental backup space. | |||
Normally du anyway does diff between various folders who have hard linked files between them. Hence if you use: | |||
<pre> | |||
cd <rsnapshot_root_folder> | |||
du -sh */<example-host>/<example-folder>/ | |||
</pre> | |||
Then the output will show full size of folder (du -sh) only for first output line. For rest all it would only be diff output. If you want to compare full folder side across all backups by adding hard-linked file space in each backup properly, we can use: | |||
<pre> | |||
cd <rsnapshot_root_folder> | |||
ls -d */<example-host>/<example-folder> | xargs -I {} du -sh {} | |||
</pre> | |||
==Retry rsync after failure== | |||
In case of lossy / bad network connection for remote backup we can use: | |||
<pre> | |||
rsync_numtries 10 | |||
</pre> | |||
where 10 can be replaced with other appropriate number based on requirement / environment. | |||
In this case as per logs only the final try related error is mentioned. Also the command is only printed once in logs if log_level is 3. The retries are managed internally by rsnapshot. | |||
Refer: | |||
* https://www.backupcentral.com/forum/18/140099/any_way_to_get_rsnapshot_to_retry_ | |||
Line 124: | Line 174: | ||
Steps learned from official rsnapshot how to at time of writing at http://rsnapshot.org/howto/1.2/rsnapshot-HOWTO.en.html#configuration | Steps learned from official rsnapshot how to at time of writing at http://rsnapshot.org/howto/1.2/rsnapshot-HOWTO.en.html#configuration | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[Backup tools]] > [[Rsnapshot]] |
Latest revision as of 04:11, 17 August 2023
Home > CentOS > CentOS 6.x > Backup tools > Rsnapshot
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:
- 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
- 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/
- 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
Delta space usage between backup copies
We can use 'rsnapshot du' or 'rsnapshot du <folder_name>' to get information about space occupied by particular folder. In this case the latest backup is shown to occupy full space, but for other older folders only the diff space is mentioned. This is useful to see both total single backup space required and also typically incremental backup space.
Normally du anyway does diff between various folders who have hard linked files between them. Hence if you use:
cd <rsnapshot_root_folder> du -sh */<example-host>/<example-folder>/
Then the output will show full size of folder (du -sh) only for first output line. For rest all it would only be diff output. If you want to compare full folder side across all backups by adding hard-linked file space in each backup properly, we can use:
cd <rsnapshot_root_folder> ls -d */<example-host>/<example-folder> | xargs -I {} du -sh {}
Retry rsync after failure
In case of lossy / bad network connection for remote backup we can use:
rsync_numtries 10
where 10 can be replaced with other appropriate number based on requirement / environment.
In this case as per logs only the final try related error is mentioned. Also the command is only printed once in logs if log_level is 3. The retries are managed internally by rsnapshot.
Refer:
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:
- Create a parent folder accessible only by root using something like
- mkdir /private
- chmod 700 /private
- Make snapshot folder for users readable by everyone using
- mkdir /private/snapshots
- chmod 755 /private/snapshots
- Then share snapshot folder using NFS as explained in Configuring basic NFSv3 server
- 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
Home > CentOS > CentOS 6.x > Backup tools > Rsnapshot