#!/bin/bash
#===============================================================================
#
# FILE: db_sync.sh
#
# USAGE: ./db_sync.sh
#
# DESCRIPTION: To sync the remote database
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: -----
# AUTHOR: Parag Kalra (), paragkalra@gmail.com, www.paragkalra.com
# COMPANY: As of now Persistent System LTD, www.persistentsys.com
# VERSION: 1.0
# CREATED: Sunday 18 January 2009 12:44:49 IST IS
# REVISION: ---
#===============================================================================
#-------------------------------------------------------------------------------
# Storing username, password & logfile in a variable
#-------------------------------------------------------------------------------
myuser=some_user
mypasswd=some_password
mylog=/var/log/projects/db_sync.log
#-------------------------------------------------------------------------------
# Executing a SQL file to create & drop local databases.
#-------------------------------------------------------------------------------
echo "Executing SQL file - `date`" > $mylog
mysql --verbose --user=$myuser --password=$mypasswd --host=localhost < /data/projects/mysql/alter_dbs.sql #---------------------------- #Dumping the remote database on the local setup #---------------------------- echo "Dumping remote mysql databases- `date`" >> $mylog
mysqldump --verbose --user=$myuser --password=$mypasswd --host=www.paragkalra.com some_database > /data/databases/pkc_db_`date +%F`.sql
#-------------------------------------------------------------------------------
# Importing the database
#-------------------------------------------------------------------------------
echo "Importing the database - `date`" >> $mylog
mysql --verbose --user=$myuser --password=$mypasswd some_database < /data/databases/pkc_db_`date +%F`.sql
echo "Export - Import of database complete - `date`" >> $mylog
Sunday, January 18, 2009
BASH script to copy a remote database !!!
Labels:
BASH,
copying a remote database,
kalra,
mysql,
parag,
paragkalra
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment