Last active
November 23, 2023 19:40
-
-
Save rstriquer/7600710 to your computer and use it in GitHub Desktop.
easydump script: Make a non consistent backupUse it with MyISAM databases. Guess this works with InnoDB, didn't tried tough
This file contains 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 | |
# - To restore the database you can use the command bellow which whill return the file | |
# whithout send any output to the screen | |
# mysql -h 127.0.0.1 -A -u root -e "USE db_name; \. databasefile.sql" | |
PROGNAME=${0##*/} | |
PROGVERSION=0.9.3 | |
usage() | |
{ | |
cat << EO | |
Usage: $PROGNAME --database DBNAME --host HOSTIP_OR_HOSTNAME --user USERNAME [options] | |
$PROGNAME --version | |
$PROGNAME --help | |
Make a non consistent backup | |
Options: | |
EO | |
cat <<EO | column -s\& -t | |
-h|--help & show this output | |
-V|-v|--version & show version information | |
-B|--database & indicates the database name | |
-h|--host & indicates the database server hostname | |
-u|--user & Optional param, passes the login user name for the database server | |
-p|--pwd & Optional param, sets the password for the user | |
-P|--port & Optional param, sets the communication port for the database server | |
--tables & Optional param, if you whishes to dump only some tables use this parameter and passes the | |
& tables names whithin a ' (simple coma) string like "--tables 'tab1 tab2'" or "--tables 'tab1'" | |
EO | |
} | |
ARGS=$(getopt -s bash --options vVB:h:u:p:P: --longoptions help,version,database:,host:,user:,pwd:,tables:,port: -q -- "$@" ) | |
eval set -- "$ARGS" | |
while true; do | |
case $1 in | |
--help) | |
usage | |
exit 0 | |
;; | |
-v|-V|--version) | |
echo "easydump version: $PROGVERSION" | |
exit | |
;; | |
-P|--port) | |
shift | |
PORT="$1" | |
;; | |
-B|--database) | |
shift | |
DATABASE="$1" | |
;; | |
-h|--host) | |
shift | |
HOST="$1" | |
;; | |
-u|--user) | |
shift | |
USERNAME="$1" | |
;; | |
-p|--pwd) | |
shift | |
PASSWORD="$1" | |
;; | |
--tables) | |
shift | |
TABLES="--tables $1" | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
shift | |
break | |
;; | |
esac | |
shift | |
done | |
if [ -z "$DATABASE" ] | |
then | |
usage | |
echo " IMPORTANTE: \"database\" parameter missing" | |
echo "" | |
exit | |
fi | |
if [ -z "$HOST" ] | |
then | |
usage | |
echo " IMPORTANTE: \"host\" parameter missing" | |
echo "" | |
exit | |
fi | |
if [ -z "$USERNAME" ] | |
then | |
usage | |
echo " IMPORTANTE: \"username\" parameter missing" | |
echo "" | |
exit | |
fi | |
if [ -z "$PORT" ] | |
then | |
PORT=3306 | |
fi | |
#cat <<EO | |
/usr/bin/mysqldump \ | |
--databases $DATABASE \ | |
--host=$HOST \ | |
--user=$USERNAME \ | |
--password=$PASSWORD \ | |
--port=$PORT \ | |
--log-error=/tmp/mysqldump\-erros.list `# records application errors in a log for later evaluation` \ | |
--force `# continues the backup even if it encounters errors along the way` \ | |
--no-create-db `# does not add "create database" command in the output script` \ | |
--skip-lock-tables `# does not lock the table (generates a non-consistent backup)` \ | |
--add-drop-table `# add a "drop table" command at the beginning of the resulting script` \ | |
--skip-comments `# avoids adding extra information such as server name, mysqldump version, etc.` \ | |
--create-options `# add all create table options` \ | |
--disable-keys `# turns off keys when restoring the backup. Makes the restore faster` \ | |
--quick `# mysql does not generate a buffer to stream it from, it streams directly from the repository itself, line by line.` \ | |
--extended-insert `# Forces a smaller and faster file to load using extended insert. More than one table row inserted by insert command` \ | |
--hex-blob `# transforms binary values into hexa (for example, 'abc' becomes 0x616263). Avoid conversion errors` \ | |
--set-charset $TABLES | |
#EO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment