MySQL DB Backups based on Conditions

MySQL DB Backups can be taken for specific schema, tables and also for a sub-set of table data. This is useful to get incremental DB Backups based on say the last read ID or Timestamp. The following code will be useful to get incremental backups in such situations:

#############################
# Get last TS info from files
#############################

lastUpdLog_ts=`cat last_t_update_log.ts`
echo $lastUpdLog_ts

lastCustRep_ts=`cat last_t_customer_report.ts`
echo $lastCustRep_ts

#############################
# Get My SQL Dump based on last timestamp info
#############################

mysqldump -hlocalhost -uroot -p"Password" "database_name" "table_name" --where="c_timestamp>'$lastUpdLog_ts'" --result-file="$HOME/incrBackups/t_upd_log_incr.sql" --no-create-info

mysqldump -hlocalhost -uroot -p"Password" "database_name" "table_name" --where="c_timestamp>'$lastCustRep_ts'" --result-file="$HOME/incrBackups/t_cust_rep_incr.sql" --no-create-info
Advertisements

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