Skip to content

Instantly share code, notes, and snippets.

@crazyrohila
Created August 5, 2013 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazyrohila/6157902 to your computer and use it in GitHub Desktop.
Save crazyrohila/6157902 to your computer and use it in GitHub Desktop.
This is shell script to take backup from server and update db to local system.
#! /bin/bash
#This is very simple script. All commands will run one by one. So If any command will fail, Script will not stop.
#You Should have install drush on server and provide ssh password.
ssh <USER>@<SERVER> "drush -r <DRUPAL_ROOT_DIR> sql-dump|bzip2 -c" > db.sql.bz2
echo 'db dump from server';
bunzip2 db.sql.bz2
echo 'unziped db';
#Delete the old db replace <password> with original password (without any space after -p).
mysqladmin -f -u <mysql-user> -p<password> drop <DB_NAME>
#Now Create New db with same name and import dumped sql file in it.
mysqladmin -u <mysql-user> -p<password> create <DB_NAME> && mysql -u <mysql-user> -p<password> <DB_NAME> < db.sql
echo 'db imported in <DB_NAME> database';
#I Don't want this file now, So delete it. If you want to keep then comment below lines.
rm db.sql
echo 'db updated and sql file removed';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment