Created
December 1, 2012 11:17
-
-
Save besstiolle/4181563 to your computer and use it in GitHub Desktop.
Script bash pour récupérer le contenu du NAS Synology et le copier sur un FTP distant
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/sh | |
###################################################################################### | |
##### Sauvegarde fichier du NAS vers le serveur dédié avec lftp | |
###################################################################################### | |
## Remarque sur lftp | |
## + Le -e de mirror efface les fichiers qui n'existent plus. | |
###################################################################################### | |
## Paramètre en entrée | |
## 1 : le répertoire à sauvegarder | |
## 2 : le répertoire distant sur le FTP | |
## 3 : -e pour effacer tous les fichiers du FTP qui n'existent plus en local ou rien | |
## | |
## exemple ./script.sh /volume1/Sauvegarde/Marion /Marion -e | |
## | |
###################################################################################### | |
# Nom du serveur et repertoire de log | |
name=CLOUD | |
dirlog=/volume1/Sauvegarde/FTP/logs | |
# Configuration : ftp / user / pass | |
servFTP=999.999.999.999 | |
userFTP=userFTP | |
passFTP=passFTP | |
# Repertoire a ignorer sur le NAS | |
# ex : repIgnore="-x wp-content/cache -x /wp-content/supercache" | |
repIgnore="" | |
# Options de la commande lftp mirroir http://lftp.yar.ru/lftp-man.html | |
options="" | |
###################################################################################### | |
# Construction fichier de log | |
horodatage=$(date +%Y_%m_%d) | |
ficLog=${dirlog}/log_${name}_${horodatage}.txt | |
# Debut shell | |
echo "+-- Deb Sauvegarde $(date) ---" >> ${ficLog} | |
# Trace de Log | |
echo "Connexion sur ftp://${userFTP}:xxxxx@${servFTP}" >> ${ficLog} | |
# Commande de copie miroir ftp vers local | |
/opt/bin/lftp ftp://${userFTP}:${passFTP}@${servFTP} -e "mirror -R ${3} ${options} ${repIgnore} ${1} ${2} ; quit" >> ${ficLog} | |
# Resultat de la commande - 0 : ok | |
res=$? | |
echo "Resultat : "${res} >> ${ficLog} | |
# A decommenter si on souhaite utiliser l'envoi d'email de Synology | |
#if [ ${res} -eq 0 ] | |
#then /usr/syno/bin/synomail SVGFini | |
#else /usr/syno/bin/synomail SVGError | |
#fi | |
# fin shell | |
echo "--- Fin Sauvegarde $(date) ---" >> ${ficLog} | |
###################################################################################### | |
exit $res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment