Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Youni's backup scripts.
- # Create backups of database & files and send them to remote server.
- # Cron runs scripts regularly. Twice a day db, once a day files.
- # Remote server should make backup of files periodically and also delete old db backups (not realised here).
- # Bash, scp, ssh, rsync, cron
- # Database backup script /home/myhostuser/db_dump
- #!/bin/sh
- #configuration
- host_address=85.85.85.58
- host_user=mysshuser
- host_port=9955
- host_dir=~/dumps
- mysql_user=mytestuser
- mysql_pass=mycoolpass
- mysql_database=mytestdb
- #code starts here
- fname=dump_$(date +%x_%H-%M-%S).sql
- tarfname=$fname.tar.gz
- echo $(date +%x_%H-%M-%S)
- echo "Making mysql dump $fname"
- mysqldump -u $mysql_user -p"$mysql_pass" $mysql_database > $fname
- tar czf $tarfname $fname
- echo "Uploading mysql dump to server"
- scp -P$host_port $tarfname $host_user@$host_address:$host_dir
- echo "Removing dump files from local machine"
- rm $fname $tarfname
- # cron job:
- # 00 03,15 * * * /home/myhostuser/db_dump >> /var/log/db_dump.log 2>&1
- # Files backup with rsync /home/myhostuser/f_dump
- #~/bin/sh
- #configuration
- host_address=85.85.85.58
- host_user=mysshuser
- host_port=9955
- host_dir=~/dumps/var/example
- files_dir=/var/example
- #code starts here
- date "+%d.%m.%Y %H:%M:%S"
- echo "Syncing new and modified files with remote server"
- rsync --rsh="ssh -p$host_port" -auv $files_dir -p $host_port $host_user@$host_address:$host_dir
- # cron job:
- # 30 03 * * * /home/myhostuser/f_dump >> /var/log/f_dump.log 2>&1
Advertisement
Add Comment
Please, Sign In to add comment