apt-get install unison
Local:
Unisson peut etre utilisé en local ou en distant à travers ssh. Commençons par l'utilisation local.
Je vais créer deux dossiers dans mon home:
mkdir ~/rep1 mkdir ~/rep2
Vous pouvez maintenant créer des sous répertoires et des fichiers dans les répertoires rep1 et rep2.
touch ~/rep1/fichier011 touch ~/rep1/fichier012 touch ~/rep2/fichier021 mkdir ~/rep1/rep01 touch ~/rep1/rep01/fichier013
ce qui donne:
tree /home/cemoi/rep1/ /home/cemoi/rep1/ |-- fichier011 |-- fichier012 `-- rep01 `-- fichier013 1 directory, 3 files tree /home/cemoi/rep2/ /home/cemoi/rep2/ `-- fichier021 0 directories, 1 file
Synchronisons le contenu de ces deux dossiers
unison ~/rep1 ~/rep2 Contacting server... Connected [//cemoi//home/cemoi/rep1 -> //cemoi//home/cemoi/rep2] Looking for changes Warning: No archive files were found for these roots, whose canonical names are: /home/cemoi/rep1 /home/cemoi/rep2 This can happen either because this is the first time you have synchronized these roots, or because you have upgraded Unison to a new version with a different archive format. Update detection may take a while on this run if the replicas are large. Unison will assume that the 'last synchronized state' of both replicas was completely empty. This means that any files that are different will be reported as conflicts, and any files that exist only on one replica will be judged as new and propagated to the other replica. If the two replicas are identical, then no changes will be reported. If you see this message repeatedly, it may be because one of your machines is getting its address from DHCP, which is causing its host name to change between synchronizations. See the documentation for the UNISONLOCALHOSTNAME environment variable for advice on how to correct this. Donations to the Unison project are gratefully accepted: http://www.cis.upenn.edu/~bcpierce/unison Press return to continue.[<spc>] Reconciling changes rep1 rep2 file ----> fichier011 [f] file ----> fichier012 [f] <---- file fichier021 [f] dir ----> rep01 [f] Proceed with propagating updates? [] y Propagating updates UNISON 2.27.57 started propagating changes at 14:22:42 on 12 Apr 2010 [BGN] Copying fichier011 from /home/cemoi/rep1 to /home/cemoi/rep2 [END] Copying fichier011 [BGN] Copying fichier012 from /home/cemoi/rep1 to /home/cemoi/rep2 [END] Copying fichier012 [BGN] Copying fichier021 from /home/cemoi/rep2 to /home/cemoi/rep1 [END] Copying fichier021 [BGN] Copying rep01 from /home/cemoi/rep1 to /home/cemoi/rep2 [END] Copying rep01 UNISON 2.27.57 finished propagating changes at 14:22:42 on 12 Apr 2010 Saving synchronizer state Synchronization complete (4 items transferred, 0 skipped, 0 failures)
Je relance la même commande pour voir la message obtenu:
unison ~/rep1 ~/rep2 Contacting server... Connected [//cemoi//home/cemoi/rep1 -> //cemoi//home/cemoi/rep2] Looking for changes scanning fichier021 Reconciling changes Nothing to do: replicas have not changed since last sync.
Il n'y a rien à faire:aucun fichier n'a été modifié depuis la dernière sauvegarde.
Pour faire des opérations plus avancées il est plus rapide de se servir du fichier de configuration d'unison qui se trouve dans ~/.unison/default.prf Nous allons créer notre propre fichier de configuration:sync_home.prf
nano ~/.unison/sync_home.prf # Unison preferences file #repertoire de destination de la replication root = /home/cemoi/replication_unison #repertoire racine de l'utilisateur root = /home/cemoi #chemin du repertoire source rep1 à repliquer dans /home/cemoi/replication_unison qui se trouve dans /home/cemoi path = rep1 #chemin du repertoire source rep2 à repliquer dans /home/cemoi/replication_unison qui se trouve dans /home/cemoi path = rep2
n'oubliez pas de créer le répertoire replication_unison:
mkdir replication_unison unison sync_home.prf Contacting server... Connected [//cemoi//home/cemoi -> //cemoi//home/cemoi/replication_unison] Looking for changes Warning: No archive files were found for these roots, whose canonical names are: /home/cemoi/replication_unison /home/cemoi This can happen either because this is the first time you have synchronized these roots, or because you have upgraded Unison to a new version with a different archive format. Update detection may take a while on this run if the replicas are large. Unison will assume that the 'last synchronized state' of both replicas was completely empty. This means that any files that are different will be reported as conflicts, and any files that exist only on one replica will be judged as new and propagated to the other replica. If the two replicas are identical, then no changes will be reported. If you see this message repeatedly, it may be because one of your machines is getting its address from DHCP, which is causing its host name to change between synchronizations. See the documentation for the UNISONLOCALHOSTNAME environment variable for advice on how to correct this. Donations to the Unison project are gratefully accepted: http://www.cis.upenn.edu/~bcpierce/unison Press return to continue.[<spc>] scanning rep1/fichier021 Reconciling changes replicati... cemoi <---- dir rep1 [f] <---- dir rep2 [f] Proceed with propagating updates? [] y Propagating updates UNISON 2.27.57 started propagating changes at 15:02:50 on 12 Apr 2010 [BGN] Copying rep1 from /home/cemoi to /home/cemoi/replication_unison [END] Copying rep1 [BGN] Copying rep2 from /home/cemoi to /home/cemoi/replication_unison [END] Copying rep2 UNISON 2.27.57 finished propagating changes at 15:02:50 on 12 Apr 2010 Saving synchronizer state Synchronization complete (2 items transferred, 0 skipped, 0 failures) Je relance la même commande pour voir la message obtenu: unison sync_home.prf Contacting server... Connected [//cemoi//home/cemoi -> //cemoi//home/cemoi/replication_unison] Looking for changes scanning rep1/fichier021 Reconciling changes Nothing to do: replicas have not changed since last sync.
Je regarde l'état du répertoire de ou la réplication à eu lieux:
tree /home/cemoi/replication_unison/ /home/cemoi/replication_unison/ |-- rep1 | |-- fichier011 | |-- fichier012 | `-- rep01 | `-- fichier013 `-- rep2 `-- fichier021 3 directories, 4 files
Tout est bien là!
Nous allons étendre les fonctions de notre fichier sync_home.prf
Rajoutons une règle pour filtrer des fichiers et/ou des répertoires:
#fichiers à ignorer ignore = Name {*.bin, toto.back, *.docx} #repertoire à ignorer ignore = Path {rep2}
Ajoutons la gestions de backup des fichiers supprimés avec la conservation des 3 dernières versions histoire de pouvoir récupérer un/des fichiers supprimés par erreur:
##gestion des backups #conservons une copie de tous les fichiers supprimes backup = Name * #conserve les 3 dernieres versions des fichiers supprimes maxbackups = 3