Home > Bash, Linux, Useful commands > How to get fresh file/mysql backup from remote on minimal effort.

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

where:
XXXXXXX is a mysql password,
database is our db to backup.

Categories: Bash, Linux, Useful commands
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: