User Tools

Site Tools


backup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
backup [2011/07/31 12:08]
sebastian Added cron job hint.
backup [2015/05/17 17:44] (current)
Line 67: Line 67:
 FTPHOST=$(grep '​^host'​ $FTPCFG | sed -e '​s/​^host//'​ -e 's/ //g') FTPHOST=$(grep '​^host'​ $FTPCFG | sed -e '​s/​^host//'​ -e 's/ //g')
 LOG_FILE='/​var/​log/​sysbackup.log'​ LOG_FILE='/​var/​log/​sysbackup.log'​
-KEEP=5 +KEEP=
- +REDIAL_ATTEMPTS=3 
 # Backup will be accessible for root only # Backup will be accessible for root only
 umask 0077 umask 0077
- +
 # Write to a log file # Write to a log file
 function write_log { function write_log {
   /bin/echo `date '​+[%Y-%m-%d %H:%M.%S]: '` $* | tee -a $LOG_FILE   /bin/echo `date '​+[%Y-%m-%d %H:%M.%S]: '` $* | tee -a $LOG_FILE
 } }
- +
 write_log "​Starting backup of $INCLUDE"​ write_log "​Starting backup of $INCLUDE"​
 write_log "​Dumping database to $DBFILE"​ write_log "​Dumping database to $DBFILE"​
Line 84: Line 85:
 write_log '​Removing database dump' write_log '​Removing database dump'
 rm $DBFILE rm $DBFILE
-  +
-# Transfer the backup file to the FTP-Server +
-# -DD deletes the file locally after successful transmission to the FTP dir. +
-write_log "​Starting FTP transfer"​ +
-ncftpput -f $FTPCFG -DD $FTPDIR $BACKUPFILE +
- +
 # Remove old files # Remove old files
 write_log "​Checking $FTPHOST for files that need to be removed"​ write_log "​Checking $FTPHOST for files that need to be removed"​
 REMFILES=$(ncftpls -f $FTPCFG -x "​-l1"​ ftp://​$FTPHOST$FTPDIR | grep backup-data | sort | head -n-$KEEP) REMFILES=$(ncftpls -f $FTPCFG -x "​-l1"​ ftp://​$FTPHOST$FTPDIR | grep backup-data | sort | head -n-$KEEP)
-write_log "​Removing files: $REMFILES"​+write_log "​Removing ​remote ​files: $REMFILES"​
 ncftpls -f $FTPCFG -W "rm $REMFILES"​ -x "​-1"​ ftp://​$FTPHOST$FTPDIR ncftpls -f $FTPCFG -W "rm $REMFILES"​ -x "​-1"​ ftp://​$FTPHOST$FTPDIR
- + 
 +# Transfer the backup file to the FTP-Server 
 +write_log "​Starting FTP transfer"​ 
 +ncftpput -r $REDIAL_ATTEMPTS -z -f $FTPCFG $FTPDIR $BACKUPFILE 
 + 
 +write_log "​Removing temporary backup archive $BACKUPFILE"​ 
 +rm $BACKUPFILE 
 write_log "​Done"​ write_log "​Done"​
 </​code>​ </​code>​
 +
 +Could be improved:
 +* The script does not recognize if the space is too small for a backup. ​
 +* No feedback (e.g. via mail) if anything goes wrong
  
 ====== MySQL backup ====== ====== MySQL backup ======
backup.txt · Last modified: 2015/05/17 17:44 (external edit)