Backup with rsnapshot: Difference between revisions

From Andreida
No edit summary
No edit summary
Line 1: Line 1:
* install
=== install ===
apt-get install rsnapshot
apt-get install rsnapshot

=== setup ===
* edit /etc/rsnapshot.conf
* edit /etc/rsnapshot.conf
** enable cmd_cp
* enable cmd_cp
** enable cmd_du
* enable cmd_du
cmd_du /usr/bin/du
cmd_du /usr/bin/du
** enable the schedule
* enable the schedule
interval hourly 6
interval hourly 6
interval daily 7
interval daily 7
interval weekly 4
interval weekly 4
interval monthly 3
interval monthly 3
** add directories to backup
* add directories to backup
backup /etc/ localhost/
backup /etc/ localhost/
backup /var/www/home/ localhost/
backup /var/www/home/ localhost/
** add script to use to generate files which you want to backup
* add script to use to generate files which you want to backup
backup_script /root/bin/backup_my_db localhost/dbbackup/
backup_script /root/bin/backup_my_db localhost/dbbackup/
* create the db-backup script, in this case /root/bin/backup_my_db
* create the db-backup script, in this case /root/bin/backup_my_db
#!/bin/bash
#!/bin/bash
mysqldump -u<USER> -p'<PASSWORD>' --all-databases > mysql_backup.sql
mysqldump -u<USER> -p'<PASSWORD>' --all-databases > mysql_backup.sql

=== cronjobs ===
* enable the cronjobs
* enable the cronjobs
0 */4 * * * /usr/bin/rsnapshot hourly
0 */4 * * * /usr/bin/rsnapshot hourly
Line 23: Line 27:
40 23 * * 6 /usr/bin/rsnapshot weekly
40 23 * * 6 /usr/bin/rsnapshot weekly
30 23 1 * * /usr/bin/rsnapshot monthly
30 23 1 * * /usr/bin/rsnapshot monthly

=== edit, tabs instead of spaces ===
* use tabs where the other lines indicate they use tab, spaces will not work
* use tabs where the other lines indicate they use tab, spaces will not work
* if you use vim to edit rsnapshot.conf, put the following into your .exrc
* if you use vim to edit rsnapshot.conf, put the following into your .exrc
Line 30: Line 36:
set noexpandtab
set noexpandtab
and then use "tab" instead of "space" where you see tabs (^I).
and then use "tab" instead of "space" where you see tabs (^I).

* for ssh backup of remote sites
=== ssh backup of remote sites ===
** enable ssh at all
* enable ssh at all
cmd_ssh /usr/bin/ssh
cmd_ssh /usr/bin/ssh
** set the parameters
* set the parameters if you really need to, prefer ~/.ssh/config
ssh_args -o BatchMode=yes -p 22
ssh_args -o BatchMode=yes -p 22
** create an entry for the backup like
* create an entry for the backup like
backup root@your-remote-host-in-config-via-ssh-key:/etc/ your-remote-host/
backup root@your-remote-host-in-config-via-ssh-key:/etc/ your-remote-host/
* install rsync at the remote host
** check the config from the shell
apt-get install rsync

=== check ===
* check the config from the shell
rsnapshot configtest
rsnapshot configtest

Revision as of 08:17, 2 March 2016

install

apt-get install rsnapshot

setup

  • edit /etc/rsnapshot.conf
  • enable cmd_cp
  • enable cmd_du
cmd_du /usr/bin/du
  • enable the schedule
interval    hourly  6
interval    daily   7
interval    weekly  4
interval    monthly 3
  • add directories to backup
backup  /etc/       localhost/
backup  /var/www/home/  localhost/
  • add script to use to generate files which you want to backup
backup_script   /root/bin/backup_my_db localhost/dbbackup/
  • create the db-backup script, in this case /root/bin/backup_my_db
#!/bin/bash
mysqldump -u<USER> -p'<PASSWORD>' --all-databases   > mysql_backup.sql

cronjobs

  • enable the cronjobs
0 */4 * * * /usr/bin/rsnapshot hourly
50 23 * * * /usr/bin/rsnapshot daily
40 23 * * 6 /usr/bin/rsnapshot weekly
30 23 1 * * /usr/bin/rsnapshot monthly

edit, tabs instead of spaces

  • use tabs where the other lines indicate they use tab, spaces will not work
  • if you use vim to edit rsnapshot.conf, put the following into your .exrc
:autocmd BufRead rsnapshot.conf set noexpandtab

or use

set list
set noexpandtab

and then use "tab" instead of "space" where you see tabs (^I).

ssh backup of remote sites

  • enable ssh at all
cmd_ssh /usr/bin/ssh
  • set the parameters if you really need to, prefer ~/.ssh/config
ssh_args -o BatchMode=yes -p 22
  • create an entry for the backup like
 backup  root@your-remote-host-in-config-via-ssh-key:/etc/    your-remote-host/
  • install rsync at the remote host
apt-get install rsync

check

  • check the config from the shell
rsnapshot configtest