Created
November 6, 2018 19:27
-
-
Save SQLadmin/3242b090a40003803e37f531f5e1c75b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# pass variables | |
archive_dbname=$1 | |
archive_table=$2 | |
archive_column=$3 | |
days_to_archive=$4 | |
archive_date="'"`date +'%Y-%m-%d' --date="-$days_to_archive day"`"'" | |
where_clause=$archive_column'<='$archive_date | |
dump_file=$archive_table_`date +'%Y-%m-%d' --date="-$days_to_archive day"`".sql" | |
# Dump the table | |
echo "DUMP Starting for the table $archive_table ....." | |
mysqldump -u root $archive_dbname $archive_table --where=$where_clause > $dump_file | |
echo "DUMP Done......" | |
# Archive the data | |
echo "Deleting the data on the table $archive_table ....." | |
mysql -u root sqladmin -e"CALL sqladmin_archive('$archive_dbname','$archive_table','$archive_column',$archive_date);" | |
echo "Deleting is Done ....." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment