SHARE
TWEET

Untitled

a guest May 27th, 2018 209 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # Backup file from ftp server using wget.
  3.  
  4. BACKUP=/tmp/backup
  5. LOG=/tmp/wget-log.$$
  6. NOW=$(date +"%Y-%m-%d")
  7.  
  8. # FTP server conf
  9. FTPD="your-ftp-directory"
  10. FTPU="your-ftp-user"
  11. FTPP="your-ftp-password"
  12. FTPS="your-ftp-server"
  13. WGET="$(which wget)"
  14.  
  15. # Other stuff
  16. EMAILID="xxxx@xxxx.com"
  17.  
  18. # Start Backup for file system
  19. [ ! -d $BACKUP ] && mkdir -p $BACKUP || :
  20. [ ! -d $BACKUP/$NOW ] && mkdir -p $BACKUP/$NOW || :
  21.  
  22. # Get backup using wget
  23. $WGET --mirror -o $LOG --no-host-directories --directory-prefix=$BACKUP/$NOW \
  24. --no-verbose --tries=5 --user=$FTPU --password=$FTPP $FTPS/$FTPD
  25.  
  26. # Find out if ftp backup failed or not
  27. if [ $? -eq 0 ]; then
  28.     echo "Backup success">>$LOG
  29.     tail $LOG | mail -s "BACKUP SUCCESS" "$EMAILID"
  30.     rm -f $LOG
  31. else
  32.     echo "Date: $(date)">>$LOG
  33.     echo "Hostname: $(hostname)" >>$LOG
  34.     echo "Backup failed" >>$LOG
  35.     tail $LOG | mail  -s "BACKUP FAILED" "$EMAILID"
  36. fi
  37.  
  38. # Remove backup older than two weeks.
  39. find $BACKUPD -maxdepth 1 -type d -daystart -ctime +2 -exec rm -rf {} \;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top