User Tools

Site Tools


doc:appunti:linux:sa:backup

Strategie di backup

Tabella comparativa

dump rsync tob rdiff-backup
Versioni vecchie di un file No
Accesso diretto al backup No Sì (full), No (inc)
Differenziale/incrementale No
Economia di banda No
Spazio necessario n*F 1*F 1*F + n*I.gz

Nello spazio necessario si indica con F la dimensione dell'archivio full, con I la dimensione dell'incrementale, con .gz il tipo di compressione e con n il numero di copie che si decide di tenere.

rdiff-backup

FIXME ATTENZIONE! Pare che rdiff-backup soffra di un Memory leak per cui non riesce a completare il backup di un dataset composto da circa 13 milioni di file per circa 700 Gb. La memoria RAM di 8 Gb viene completamente consumata e il processo muore. Questo almeno accade con rdiff-backup 1.2.8-6 e python 2.6.6-3+squeeze7 su Debian Squeeze.

Si installa il pacchetto Debian rdiff-backup. Un primo script di backup di una directory verso un host remoto potrebbe essere questo:

rdiff-backup --force \
    --preserve-numerical-ids \
    --exclude /home/crypt \
    /home \
    epidauro.rigacci.net::/media/hdc1/backup/paros

Nella directory destinazione viene creata una gerarchia di directory uguale alla sorgente, con tutti i file nella loro ultima versione. Per escludere qualcosa dalla directory sorgente vedere anche l'opzione –exclude-filelist.

Se rdiff-backup viene eseguito nuovamente si ottiene un backup incrementale. Le vecchie copie dei file modificati vengono salvati nella directory rdiff-backup-data (come file diff oppure snapshot, se sono cambiati di poco o molto). Altri dati vengono salvati per sapere quali file o directory sono stati creati o cancellati.

Per vedere quali backup incrementali sono stati effettuati:

rdiff-backup -l root@epidauro.rigacci.net::/media/hdc1/backup/paros
Found 3 increments:
    increments.2006-08-25T18:55:44+02:00.dir   Fri Aug 25 18:55:44 2006
    increments.2006-08-26T12:51:09+02:00.dir   Sat Aug 26 12:51:09 2006
    increments.2006-09-20T19:54:15+02:00.dir   Wed Sep 20 19:54:15 2006
Current mirror: Fri Oct 20 15:16:26 2006

Per vedere quali vecchie versioni di un file esistono (attenzione: il timestamp mostrato è il momento in cui è stato fatto il backup, non il timestamp del file salvato):

rdiff-backup -l epidauro.rigacci.net::/media/hdc1/backup/paros/dokuwiki/data/pages/start.txt
Found 2 increments:
    start.txt.2006-08-26T12:51:09+02:00.diff.gz   Sat Aug 26 12:51:09 2006
    start.txt.2006-09-20T19:54:15+02:00.diff.gz   Wed Sep 20 19:54:15 2006
Current mirror: Fri Oct 20 15:16:26 2006

Per recuperare una vecchia copia di un file e salvarla in una directory a scelta (si specifica il timestamp di un backup incrementale):

rdiff-backup --restore-as-of 2006-09-20T19:54:15+02:00 \
    epidauro.rigacci.net::/media/hdc1/backup/paros/dokuwiki/data/pages/start.txt \
    ./tmp/start.txt

Per recuperare una directory eliminata (si specifica il timestamp di un backup incrementale):

rdiff-backup --restore-as-of 2006-10-12 \
    root@epidauro.rigacci.net::/home/backup/paros/niccolo/geodati/osm/regioni .

Per eliminare le vecchie copie incrementali (es. oltre i 20 giorni):

rdiff-backup --remove-older-than 20D epidauro.rigacci.net::/media/hdc1/backup/paros

dump/restore

Come fare il restore interattivo e selettivo di una directory (pippodir) dentro un dump:

restore -i -f /backup/argo/2007-01-26_md3.dump
restore > cd directory
restore > ls
restore > add pippodir
restore > extract
You have not read any volumes yet.
Unless you know which volume your file(s) are on you should start
with the last volume and work towards the first.
Specify next volume # (none if no more volumes): 1
set owner/mode for '.'? [yn] y
restore > quit

Baubackup

The program is writter in Perl and you can download it here: baubackup.tar.gz.

Based on the same principle of FauBackup: make a snapshot backup to a filesystem, then make incremental snapshots where unchanged files are only hard-linked with the existing version of the file.

This program will address the major problem of FauBackup: speed. Faubackup first of all make a full copy of every file, then it removes unchanged ones making hard links. This is undesiderable for remote backups.

Here we use cp -a to make a new snapshot based on the last one, then we use the rsync program to syncronize the snapshot with the actual filesystem.

Usage

Usage: baubackup machine:/remote/dir
       baubackup --clean

The machine can be the name of a remote machine or localhost, for backing-up a locally mounted filesystem. The target directory is specified into the configuration file.

With the --clean option, all the obsolete backups will be removed from the target directory.

Configuration

Configuration file is saved into /etc/baubackup:

# Configuration for baubackup
package BAUBACKUP;
 
# default directory for backups
# MACHINE is replaced by the machines hostname
# DIR is replaced by the source directory, with '/' made '-'
#$backup        = "/backup/MACHINE/DIR"; # <-- to use one directory per host
$backup         = "/backup/MACHINE:DIR";
 
# keep old backups for that long:
# (0 means: only keep a backup for current year/month/etc.,
# -1 means: don't store backups for that year/month/etc.)
$keepyears      = 2;
$keepmonths     = 2;
$keepweeks      = 2;
$keepdays       = 5;
 
# make perl happy
1;

The destination directory prefix is declared with the variable $backup into the configuration file. The subdirectory name is composed also by the name of the host and the source directory. Slashes in the directory are replaced with dashes, so - in the above example - a backup of somehost:/home/niccolo will be stored into a local directory named /backup/somehost:home-niccolo/. Each snapshot will be stored into a different subdirectory named something like 2007-05-24@10:15:39.

If the hostname is different from localhost, an ssh connection is attempted. Prepare the required rsa keys infrastructure if you want automated backup without password requests.

Exclude files

If you want some files to be excluded from the backup, create a file called exclude and save it into the $backup directory. For the syntax of this file see the --exclude-from option into the rsync(1) man page.

backup-manager

Da usare in sostituzione di tob che non è più presente in Debian Squeeze (dipende da afio che ha una licenza non libera).

backup-manager ha il vantaggio di poter usare dar come programma di archivio (al posto di tar) con i seguenti vantaggi:

  • Suddivide gli archivi in slice (file) di dimensione prefissata.
  • È in grado di accedere rapidamente ad un file all'interno di un archivio.
  • Può creare archivi differenziali e incrementali, gestendo i file eliminati.

Per ogni task di backup si può creare un file di configurazione del tipo /etc/backup-manager/home.conf (prendere ad esempio /etc/backup-manager.conf), con all'incirca questi parametri:

export BM_REPOSITORY_ROOT="/home/backups/home"

export BM_ARCHIVE_METHOD="tarball"
export BM_TARBALL_FILETYPE="dar"

BM_TARBALL_TARGETS[0]="/home"
export BM_TARBALL_BLACKLIST="/home/backups /home/gisdata /home/postgresql"

export BM_UPLOAD_METHOD="ftp"
export BM_UPLOAD_HOSTS="ftpback.rigacci.org"
export BM_UPLOAD_FTP_USER="ftpuser"
export BM_UPLOAD_FTP_PASSWORD="******"
export BM_UPLOAD_DESTINATION="/paros/backups/home"

Purtroppo non è possibile indicare la directory radice nell'array BM_TARBALL_TARGETS[] e poi escludere qualche sottodirectory con BM_TARBALL_BLACKLIST (vedere bug 608237).

Purtroppo viene creato un archivio per ogni BM_TARBALL_TARGETS[], rendendo un po' affollata la directory destinazione.

Per vedere il contenuto di un archivio dar (le varie slice hanno estensione .1.dar, .2.dar, ecc.):

dar -l paros-home.20110428.master

Per estrarre tutto il contenuto di un archivio dar nella directory corrente:

dar -x /home/backups/paros-home.20110430.master

Per estrarre una directory oppure un file da un archivio dar nella directory corrente (crea le directory necessarie):

dar -x /home/backups/paros-home.20110430.master -g niccolo/Maildir/
dar -x /home/backups/paros-home.20110430.master -g niccolo/document.pdf

rsync su MS-Windows

Vedere la soluzione basata su cwRsync - Rsync for Windows.

Per abbinare rsync ad una connessione sicura si può usare il software non libero (ma gratuito) freeSSHd.

Rimane il problema di fare il backup dei locked files, le versioni di Windows da XP e 2003 offrono il servizio di Volume Shadow Copy Service (VSS) che dovrebbe risolvere il problema, ma è necessario che il software rsync sia compatibile con VSS.

Dovrebbe essere possibile usare una soluzione basata su VShadow, un tool generico che consente di attivare uno snapshot di un disco prima di eseguire il tradizionale cwRsync. Purtroppo tale soluzione si basa sul pacchetto wmi-client che è stato rimosso da Debian perché bloccato ad una vecchia versione di Samba per motivi di licenza. Il pacchetto wmi-client contiene winexe, un tool per eseguire da GNU/Linux un programma su host remoto Windows.

In alternativa - a giudicare da questo post - dovrebbe esistere una versione di rsync che supporta VSS nativamente.

Winexe

Esisten un pacchetto wmi-client compilato per Ubuntu che ha pochissime dipendenze e si installa bene anche su Debian Squeeze.

In alternativa dal sito winexe su SourceForge si arriva ad un repository di pacchetti precompilati per varie distribuzioni.

Ecco un esempio di come eseguire Notepad su Windows remoto, aprendo un file condiviso su network share:

winexe --interactive=1 --system \
    --user=Administrator%administrator //192.168.3.114 \
    'notepad \\naxos\Public\prova.txt'

Il comando funziona copiando e lanciando un eseguibile (winexesvc.exe) sulla macchina Windows. Il servizio resta in ascolto per eventuali nuove invocazioni.

Se il comando dovesse fallire con il messaggio di errore

ERROR: Failed to install service winexesvc - NT_STATUS_IMAGE_ALREADY_LOADED

verificare se il parametro --reinstall risolve il problema.

Account Administrator e Windows 7

Pare che non sia possibile eseguire un processo winexe --interactive=1 con Windows Vista e Windows 7, perché il processo parte ma non nel desktop dell'utente attivo.

Ad ogni modo, per eseguire il programma senza privilegi di amministratore (con Windows 7 l'account Administrator esiste ma è disabilitato) bisogna aggiungere questa chiave nel registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system\LocalAccountTokenFilterPolicy impostando una DWORD=1.

Per abilitare l'account Administrator in Windows 7 Professional vedere Local Users and Groups, in pratica bisogna cercare ed eseguire lusrmgr.msc.

VSS

Segue una descrizione dei pregi e difetti di VSS (tratta dal sito di Ferro Backup):

As we have already mentioned, this service allows backup of locked files, but both the back-up program and the program that locked the file must be VSS-compliant. This means that the application (e.g. the database application) whose files we want to back up must be dedicated for the Windows XP/2003 platform and use shadow copy mechanisms.

Another VSS limitation is that the backup application, the application that has locked the file and the file itself all have to be on the same computer.

Another inconvenience is that volume shadow copying requires adequate free disc space. This space is used to make volume snapshots. If there’s not enough free space on the disc, then backup of locked files will not be possible, either.

  • The service is only available in Windows XP and Windows Server 2003
  • The backup software and business software must be VSS-compliant
  • The backup software, business software and the locked file must be on the same computer./
  • Additional disc space is required
doc/appunti/linux/sa/backup.txt · Last modified: 2013/09/03 12:46 by niccolo