Script bash pour récupérer le contenu d'un FTP distant depuis un Synology
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 d'un site web distant par FTP avec lftp | |
###################################################################################### | |
## Remarque sur lftp | |
## + Le -e de mirror efface les fichiers qui n'existent plus. | |
###################################################################################### | |
## Paramètre en entrée | |
## 1 : -e ou rien | |
## pour effacer tous les fichiers du local qui n'existent plus sur le FTP | |
###################################################################################### | |
# nom du serveur et repertoire local + ftp | |
name=SERVER97 | |
dir=/volume1/Sauvegarde/FTP/ | |
repFTP=/ | |
# configuration : ftp / user / pass | |
servFTP=192.168.9.9 | |
userFTP=login | |
passFTP=password | |
horodatage=$(date +%Y_%m_%d_%H_%M) | |
ficLog=${dir}logs/log_${name}_${horodatage}.txt | |
repLocal=${dir}/${name}/${horodatage}/ | |
#Repertoire a ignorer sur le FTP | |
# 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="" | |
options=--Remove-source-files | |
###################################################################################### | |
# debut shell | |
echo "+-- Deb Sauvegarde $(date) ---" >> ${ficLog} | |
# Creation du repertoire | |
mkdir ${repLocal} | |
# On se place au repertoire de sauvegarde | |
cd ${repLocal} | |
# 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 ${1} ${options} ${repIgnore} ${repFTP} ${repLocal} ; quit" >> ${ficLog} | |
# résultat 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 |
ça aurait été sympa de me citer dans ton article !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code initialement trouvé sur http://www.cobestran.com/actualite/synology-sauvegarde-site-web-par-ftp-avec-lftp/