Skip to content

Instantly share code, notes, and snippets.

@tareqy
Created August 30, 2018 16: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 tareqy/b3ae3b360d7eaa2766d92fb310d95ffb to your computer and use it in GitHub Desktop.
Save tareqy/b3ae3b360d7eaa2766d92fb310d95ffb to your computer and use it in GitHub Desktop.
Shell Script MySQL single tables backup
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 <database> [output-path]"
exit 1
fi
TABLES=`mysql -uroot -ppassword -B -N -e "select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA='$1' AND TABLE_NAME <> 'project_users_views_archive_non';"`
OUT="$2"
if [ "$OUT" == "" ]; then
OUT="."
fi
if [ ! -d $OUT ]; then
echo "$OUT does not exist"
exit 1
fi
for table in $TABLES; do
echo -n "dumping $1.$table..."
mysqldump -uroot -ppassword --add-drop-table $1 $table | gzip > $OUT/$1.$table.sql.gz
echo "done"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment