How to get fresh file/mysql backup from remote on minimal effort.
Lets assume that we have a remote web server (with ssh access) and we want fresh backup of files and mysql databases. Of course we can login, type some commands and then sftp those files but lets do this on minimum effort:
Backup files (tar, gzip and ‘download’ them):
ssh user2@remote "tar cf - /var/www/somepage | gzip -c" > files.tar.gz
Backup MySQL database:
ssh user2@remote "mysqldump -pXXXXXX database | gzip -c" > mysql.gz
Lets merge those command and write a little bash script that will automate those activities:
#!/bin/bash now=$(date +"%Y%m%d%H%M") bckdir="/home/user/backups" ssh user2@remote "mysqldump -pXXXXXX databases | gzip -c" > $bckdir/$now.mysql.gz ssh user2@remote "tar cf - /var/www/somepage | gzip -c" > $bckdir/$now.files.tar.gz
XXXXXXX is a mysql password,
database is our db to backup.