Forum Discussion
Jan 28, 2015
Hi,
recently I had to use SFTP to store a scheduled backup to a remote server via SFTP. The script is continuously executed via cron. Two things to consider: 1. cron settings are not stored in .ucs archive (will not be saved / migrated) 2. known hosts are not stored in .ucs archive (will not be saved / migrated) That´s why an additional script is used to update cron and known hosts (pls let me know, if this is required as well). Regarding the script below: SFTP uses a batch file which is dynamically created each time the script runs. It relies on exporting the own SSH public key to the remote destination. Make sure key based authentication via SSH works for root before running the script.! /bin/bash
save current configuration to /shared/backup/ directory
( /shared/backup/ needs to be created in advance )
sftp archive to remote server
delete archives older 7 days
log archive removal to /var/log/ucsdelete
copy script to /shared/autobackup.sh
make script executable
chmod 775 /shared/autobackup.sh
modify cron (crontab -e) to save config i.e. two times per day
5 */12 * * * /shared/autobackup.sh
time=`date +%Y%m%d_%H%M`
unit=`echo "$HOSTNAME" | awk -F '.' '{print $1}'`
tmsh save /sys ucs /shared/backup/autoarchive_${unit}_${time}.ucs
cat > /shared/backup/sftpbatch << EOF
put /shared/backup/autoarchive_${unit}_${time}.ucs /remote/backup/autoarchive_${unit}_${time}.ucs
EOF
if sftp -b /shared/backup/sftpbatch root@10.200.200.172
then
logger -p local0.notice "0108500:5: Remote config backup success for file /shared/backup/autoarchive_${unit}_${time}.ucs"
else
logger -p local0.warning "0108500:4: Remote config backup failed for file /shared/backup/autoarchive_${unit}_${time}.ucs"
fi
find /shared/backup/ -name "autoarchive*" -mtime +7 -ls >> /var/log/ucsdelete
find /shared/backup/ -name "autoarchive*" -mtime +7 -ls -exec rm -f {} \;
Thanks, Stephan