Last active
April 4, 2016 07:28
-
-
Save zuzu59/40406827f0399dca3da589180f26538e to your computer and use it in GitHub Desktop.
zlitebackup.sh, script de sauvegarde (backup) économique automatique de Full/Différentiel avec rsync et ssh, zf160330.1432
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa | |
#ssh-copy-id -i username@backuphost | |
echo "Script de backup économique automatique de Full/Différentiel" | |
echo "Use: ./zlitebackup.sh" | |
echo "zf 1200711.1704,150209.0838,150625.2241,160330.1432" | |
GREEN='\033[1;32m' | |
NOCOL='\033[0m' | |
echo -e ${GREEN}$0 "start...$(date)"${NOCOL} | |
########################### | |
# Paramètres à modifier ! # | |
########################### | |
# Simplement commenter la ligne SIMULATION pour ne plus simuler le backup ! | |
#SIMULATION='-n' | |
SOURCE='/Users/zuzu' | |
TARGET_MACHINE='root@ditsup-naszf2.epfl.ch' | |
TARGET='/volume1/zuzu/Backups/iMac-Zf' | |
#EXCLUDE='--exclude=**/ImapMail/ --exclude=**/zlitebackup/ --exclude=**/*tmp* --exclude=**/.cache* --exclude=**/cache* --exclude=**/Cache* --exclude=**/lost+found* --exclude=**/*rash* --exclude=**/mnt/* --exclude=**/.VirtualBox* --exclude=**/VirtualBox* --exclude=**/.evolution* --exclude=**/.mozilla* --exclude=**/.opera* --exclude=**/.macromedia* --exclude=**/.navicat* --exclude=**/google-earth* --exclude=**/.local/share/gvfs* --exclude=**/.thumbnails* --exclude=**/Picasa2/db3* --exclude=**/.gvfs* --exclude=**/.wine* --exclude=**/chromium/*' | |
EXCLUDE='--exclude=**/Library* --exclude=**/mnt* --exclude=**/.Trash* --exclude=**/VirtualBox?VM?Masters* --exclude=**/VirtualBox?VMs*' | |
########################### | |
YEAR=`date +%Y` | |
MONTH=`date +%m` | |
DAY=`date +%d` | |
TIME=`date +%H-%M-%S` | |
DIFF='diff/'${YEAR}/${MONTH}/${DAY}/${TIME} | |
COMMAND='-r -t -v --progress --stats --size-only --modify-window=1 --delete-excluded' | |
#COMMAND='-r -t -v --progress --stats --checksum --modify-window=1 --delete-excluded' | |
echo 'Créé la structure de backup...' | |
ssh $TARGET_MACHINE mkdir -p $TARGET/full | |
ssh $TARGET_MACHINE mkdir -p $TARGET/$DIFF | |
echo 'Backup via le rsync...' | |
RSYNC_CMD="rsync $SIMULATION $COMMAND $EXCLUDE --backup --backup-dir=$TARGET/$DIFF/ -e ssh $SOURCE $TARGET_MACHINE:$TARGET/full" | |
echo $RSYNC_CMD | |
$RSYNC_CMD | |
echo 'Set les bons privilèges sur la structure de backup' | |
ssh $TARGET_MACHINE chown -R zuzu $TARGET | |
#ssh $TARGET_MACHINE chgrp -R users $TARGET | |
echo "" | |
echo -e ${GREEN}$0 "end...$(date)"${NOCOL} | |
echo "" | |
echo " | |
Si jamais pour info: | |
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa | |
ssh-copy-id -i username@backuphost | |
crontab -e | |
0 8-19/1 * * 1-5 /Users/zuzu/zlitebackup.sh (backup la journée du L-V) | |
0 20-22/2 * * * /Users/zuzu/zlitebackup.sh (backup la nuit tous les jours) | |
0 0-6/2 * * * /Users/zuzu/zlitebackup.sh (backup la nuit tous les jours) | |
* * * * * /Users/zuzu/zlitebackup.sh (pour les tests) | |
" | |
echo "" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plus d'information sur son utilisation sur MAC OS X pour sauvegarder très facilement son Macintosh.
http://wiki.epfl.ch/macunix#zlitebackup
Fonctionne aussi sur Linux !