#!/bin/bash dossier_local="/data/clone-ftp" server="ftp.server" #server name source_distant="" #remote directory to backup (let empty for all the ftp root) credential_file="/data/clone-ftp.secret" #format user:password logfile="/var/log/clone-ftp.log" #logfile foldersExcluded="backup_ftp public_html/private/backups public_html/monlinux.net/files" #exclude directory or files quick="no" #value "on"/"yes" or "off" to only check only new files, not modified (quicker) #test if local directory exist if [ ! -d "$dossier_local" ] ; then echo "Error : directory $dossier_local don't exist!" >&2 exit 1 fi #test if credential file exist if [ ! -e "$credential_file" ] ; then echo "Error : FTP credential file $credential_file don't exist!" >&2 exit 1 fi #get args to check about quick mode if [ $# == 1 ] ; then if [ "$1" == "--quick" ] ; then quick="yes" else echo "bad args, use --quick for only check new files" >&2 && exit 1 fi fi credential=$(cat $credential_file) #get excluded if [ "$foldersExcluded" != "" ] ; then while read exclude ; do formatFoldersExcluded="$formatFoldersExcluded --exclude '$exclude'" done < <(echo "$foldersExcluded") fi #get quick mode : only add new files, don't compare files modified if [ "$quick" == "yes" ] || [ "$quick" == "on" ] ; then quickValue='--only-missing' ; fi #lftp -c mirror --continue --delete $quickValue --log="$logfile" "$formatFoldersExcluded" ftp://$credential@$server/$source_distant $dossier_local lftp -u $credential $server <