A data or web server needs several kinds of backups, depending what problem the backup is aimed to fix.

On this page... (hide)

  1.   1.  Backup from a date
  2.   2.  Local backups
  3.   3.  Rsync scripts and ssh
  4.   4.  Home
  5.   5.  System
  6.   6.  Restore
  7.   7.  Variants

1.  Backup from a date

time find . -type f newermt 2012-01-01 ! -newermt 2017-01-01 -print0 | rsync -HAXaxi --delete --from0 --files-from=- . /run/media/jdd/0ae3a54f-b032-4a21-8180-14d5efc5577f

2.  Local backups

Backing up, or better said archiving with large usb disks is a good idea.

Better mount the source disk as read only, in my case better do as user as I'm the only user of this computer, so all the files are owned by me. See Mount a disk as user, read only.

After that (and only after that), plug or switch on the target disk and mount it read/write.

Then

rsync -av --delete /run/media/jdd/intenso5to2/ /run/media/jdd/intenso4to/

with the right mount points. Preferably usb3! And wait.

I sometime change some folder names. If I remember this on time, it's better to do the same manually on the target, else the old folder will be removed and replaced, but it may be longer.

3.  Rsync scripts and ssh

Most backups are done with rsync scripts, preferably to an external server (other than the one being backed). So you may need to setup a ssh authentification key without pass phrase to connect the two computers (see).

and with cron:

 MAILTO = jdd@dodin.org
 30 01 * * * /root/bin/backup-to-kim7.sh

in the script script, two lines:

rsync -azv --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" /home/ kim5@kim7.dodin.org:/home/kim5/backup/home/
rsync -azv --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" -x / kim5@kim7.dodin.org:/home/kim5/backup/system/

4.  Home

By home, I mean home and all the eventual data, I mostly try to setup data folders in /home for convenience (in the server). There are probably in /home no special file needing special treatment, but the files may be large or in large number. These files mostly have to survive a server upgrade.

rsync -avz --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" /home user@dodin.org:~/data/

fake-super is there to keep superuser permissions if any.

save it in a script bash in bin

In cron:

 30 01 * * * /root/bin/backup-home

5.  System

In system, the key is "-x' that mean "no external file system", for example do not go to mounted parts (so no /home) nor extra file systems like /dev or /proc.

rsync -avz --delete --rsync-path="rsync --fake-super"   -e "ssh -i /root/.ssh/id_dsa" -x / nemo-bk@dodin.org:/data/nemo-bk/system

6.  Restore

If using fake-super, this option have also to be used at restore time. Si vous utilisez --delete, soyez très prudent quand au répertoire où vous faites la restauration, ici le répertoire wordpress. Le "." à la fin de la commande signifie que vous devez vous trouver dans ce répertoire pour la lancer!

 rsync -avz --delete --rsync-path="rsync --fake-super" -e "ssh -i /root/.ssh/id_dsa" kim5@kim7.dodin.org:/home/kim5/backup/home/data/srv/www/htdocs/wordpress/ .

7.  Variants

rsync -av --max-size=400m --delete --exclude=/media --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --delete-excluded --exclude='*/Cache/*' --exclude=/windows/C/pagefile.sys / /media/opensuse11/

ajouter "-n" (dry run) au premier essai

sauvegarde du serveur:

rsync -av --exclude=/media --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --exclude=/data --exclude=/extra --exclude=/home / .

-e ssh root@dodin:/ pour passer par ssh

attention, ca exclu /data

pour les données:

rsync -av --exclude k2_root/ --exclude backup/ -e ssh root@dodin.org:/data/ .

Usage de l'option "-x" (one file system)?

se placer dans le répertoire de réception et

rsync -av -x --delete origine destination

Sauvegarde du serveur du culte:

m-r (dans m-r, script cron):

rsync -avz -e "ssh -i /root/.ssh/id_dsa" / cu1lt2@dodin.org:/data/culte-serveurs-bk/m-r/ --exclude=/proc --exclude=/dev --exclude=/sys --exclude=/tmp --exclude=/var/tmp --delete-excluded --exclude='*/Cache/*' --max-size=400m --delete