Backup with rsnapshot
From Andreida
prepare install from backport
If the package is only in the backport, you will have to use that: Debian#Use_a_backport
install
apt-get install rsnapshot
edit, tabs instead of spaces
This is important: USE TABS BETWEEN COLUMNS!
- 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).
prepare ssh to other servers IF NEEDED
If you want to backup other servers, you will need to connect with ssh to them. Prepare a ssh-key without password, add the public version of it to the authorized_keys of the other system's correct user and create/modify a ~/.ssh/config which allows to ssh into the other system with a simple command like
ssh server-wiki
where user, port, identity file and ServerAliveInterval are all set in the config file already.
Example:
Host * ServerAliveInterval 15 IdentityFile ~/.ssh/id_rsa Host server-wiki HostName wwww.your-super-cool-server.com Port 22 User root Host server-games HostName games.your-super-cool-2nd-server.net Port 1022 User admin
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
- or instead of scripting, use multiple exec commands:
backup_exec ssh server-wiki "rm -rf /var/db-dump/" backup_exec ssh server-wiki "mkdir /var/db-dump/" backup_exec ssh server-wiki "mysqldump -uroot -p'YourPassword' wiki_1 > /var/db-dump/mysql_backup-wiki-1.sql" backup_exec ssh server-wiki "mysqldump -uroot -p'YourPassword' wiki_2 > /var/db-dump/mysql_backup-wiki-2.sql" backup server-wiki:/var/db-dump/ server-wiki/
And make always sure to use tabs between columns.
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
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
- there is no need to give "-F /home/backup/.ssh/config" or "-F /root/.ssh/config", it will be used automatically
ssh_args -o BatchMode=yes -p 22
- I have mine disabled
# ssh_args
- 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
- make sure the remote system has the needed hostkeys
ssh-keygen -A
- give absolute full paths for "IdentityFile" in your config
check
- check the config from the shell
rsnapshot configtest
This is what I use during creation of my backup script(s):
clear;rsnapshot configtest && rsnapshot -v hourly && echo ----- && du -hcs /var/cache/rsnapshot/*