Skip to content

Instantly share code, notes, and snippets.

@bensbrowning
Last active November 6, 2019 07:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bensbrowning/10996904 to your computer and use it in GitHub Desktop.
Save bensbrowning/10996904 to your computer and use it in GitHub Desktop.
lftp mirror script for cron
#!/bin/bash
login="user"
pass="pass"
host="foo.bar.com"
remote_dir="/path/on/foo/bar/"
local_dir="/home/you/foobar-mirror/"
log_file="/tmp/lftp-mirror.log"
trap "rm -f /tmp/lftp-mirror.lock" SIGINT SIGTERM
if [ -e /tmp/lftp-mirror.lock ]
then
echo "mirror is running already, rm /tmp/lftp-mirror.lock if this is false."
exit 1
else
touch /tmp/mirror
lftp -p 22 -u $login,$pass sftp://$host << EOF
set mirror:use-pget-n 5
mirror -c -P5 --Remove-source-files --log="$log_file" $remote_dir $local_dir
quit
EOF
rm -f /tmp/lftp-mirror.lock
trap - SIGINT SIGTERM
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment