Skip to content

Instantly share code, notes, and snippets.

@besstiolle
Created November 24, 2012 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besstiolle/4141366 to your computer and use it in GitHub Desktop.
Save besstiolle/4141366 to your computer and use it in GitHub Desktop.
Script bash pour récupérer le contenu d'un FTP distant depuis un Synology
#!/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
@besstiolle
Copy link
Author

@cobalt74
Copy link

ç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