Aller au contenu | Aller au menu | Aller à la recherche

Krusaf's Blog

lundi, juin 30 2008

par2 : un utilitaire qui peut être fort utile !

par2 is a program for creating and using PAR2 files to detect damage in data files and repair them if necessary. It can be used with any kind of file.

par2 est une petite application qui permet réparer un(des) fichier(s) qui aurait pu être altérés. Par exemple, je grave un CD de mes sauvegardes et malheureusement, le CD a subit quelques rayures et les fichiers ont été endommagés. je ne peux plus décompresser le fichier. Si j'avais utiliser l'utilitaire par2, j'aurais peut-être pu réparer mes si précieuses sauvegardes.

comment ça marche ? par2 créé simplement quelques fichiers en plus permettant, si le fichier est endommagé, de le réparer. En fait, cest basé sur des calculs de CRC, il me semble avoir étudié ça en IUT ou autre .... :)

Installation (sous debian et dérivé) : apt-get install par2

Créer les fichiers par2 : par2 c fichier.tar (Je prends exemple avec un fichier tar, cela pourrait être autre chose hein ... voirplusieurs fichiers)

Vérifier que le fichier ne soit pas endommagé : par2 v premier_fichier.par2

krusaf@ares:/home/bkp$ ll _etc_20080630_.tar.gz*
-rwx------ 1 root root 3992006 2008-06-30 22:50 _etc_20080630_.tar.gz
-rwx------ 1 root root   40436 2008-06-30 22:50 _etc_20080630_.tar.gz.par2
-rwx------ 1 root root   42500 2008-06-30 22:50 _etc_20080630_.tar.gz.vol000+01.par2
-rwx------ 1 root root   84900 2008-06-30 22:50 _etc_20080630_.tar.gz.vol001+02.par2
-rwx------ 1 root root  129364 2008-06-30 22:50 _etc_20080630_.tar.gz.vol003+04.par2
-rwx------ 1 root root  177956 2008-06-30 22:50 _etc_20080630_.tar.gz.vol007+08.par2
-rwx------ 1 root root  234804 2008-06-30 22:50 _etc_20080630_.tar.gz.vol015+16.par2
-rwx------ 1 root root  308164 2008-06-30 22:50 _etc_20080630_.tar.gz.vol031+32.par2
-rwx------ 1 root root  318484 2008-06-30 22:50 _etc_20080630_.tar.gz.vol063+37.par2
krusaf@ares:/home/bkp$ sudo par2 v _etc_20080630_.tar.gz.par2
par2cmdline version 0.4, Copyright (C) 2003 Peter Brian Clements.

par2cmdline comes with ABSOLUTELY NO WARRANTY.

This is free software, and you are welcome to redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version. See COPYING for details.

Loading "_etc_20080630_.tar.gz.par2".
Loaded 4 new packets
Loading "_etc_20080630_.tar.gz.vol063+37.par2".
Loaded 37 new packets including 37 recovery blocks
Loading "_etc_20080630_.tar.gz.vol003+04.par2".
Loaded 4 new packets including 4 recovery blocks
Loading "_etc_20080630_.tar.gz.vol015+16.par2".
Loaded 16 new packets including 16 recovery blocks
Loading "_etc_20080630_.tar.gz.vol001+02.par2".
Loaded 2 new packets including 2 recovery blocks
Loading "_etc_20080630_.tar.gz.vol007+08.par2".
Loaded 8 new packets including 8 recovery blocks
Loading "_etc_20080630_.tar.gz.vol031+32.par2".
Loaded 32 new packets including 32 recovery blocks
Loading "_etc_20080630_.tar.gz.vol000+01.par2".
Loaded 1 new packets including 1 recovery blocks

There are 1 recoverable files and 0 other files.
The block size used was 1996 bytes.
There are a total of 2001 data blocks.
The total size of the data files is 3992006 bytes.

Verifying source files:

Target: "_etc_20080630_.tar.gz" - found.

All files are correct, repair is not required.

Réparer un fichier : par2 r premier_fichier.par2

Et pour les allergiques à la ligne de commande ( Merci schyzo) : pypar2 : http://pypar2.silent-blade.org/ gpar2 : http://sourceforge.net/project/show

Biensûr, ce billet ne remplace par le manuel ;) RTFM : man par2

jeudi, février 8 2007

backup mysql

Script de backup de base de donnée mysql avec historique sur plusieurs jours :

J'avais du créer le fichier .my.cnf lors de l'installation d'une application (mais je ne me rappelle plus laquelle). Donc je suis parti de ce fichier pour écrire mon script.

Le script de backup n'est pas très difficile à comprendre :

  1. On récupère les variables de connexion à la base de donnée
  2. On récupère la date qui permettra de nommer le futur fichier de backup
  3. On dump la bdd
  4. On trouve puis efface les fichiers trop vieux.

Le script permet ainsi de sauvegarder sa bdd de manière journalière (en écrivant une ligne dans le cron) tout en maitrisant l'espace disque. Vous pouvez modifier le script à votre guise en rajoutant une ligne pour compresser...


## Recupere info connection mysql
USER=$(awk -v arg=user -F '=' '($1==arg){ print $2 }' /root/.my.cnf)
HOST=$(awk -v arg=host -F '=' '($1==arg){ print $2 }' /root/.my.cnf)
PASS=$(awk -v arg=password -F '=' '($1==arg){ print $2 }' /root/.my.cnf)
DESTINATION="/repertoire/de/backup"
NB="28"

# Date
d=$(date "+%Y%m%d")

mysqldump -a -c --add-drop-table -h${HOST} -p${PASS} -u${USER}  -A > ${DESTINATION}/${d}.sql
chmod 700 ${DESTINATION}/${d}.sql

# On garde nb jours de backup
find ${DESTINATION} -type f -mtime +${NB} | awk '{ 
  if($1!="/" && $1!="/home" && $1!="/etc")
  {
    system("rm -f "$1);
  }
}'

Le fichier /root/.cnf :


zeus:~/bkpmysql# cat /root/.my.cnf 
[client]
host=localhost
user=root
password=********