├── .gitignore ├── 7zip-log-to-file.sh ├── cron.sh ├── cron ├── zzmysqldump.default.conf ├── setup.sh ├── zzmysqlclean.sh ├── zzmysqlimp.sh ├── zzmysqldump.sh └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | zzmysqldump.conf 2 | profile*.conf -------------------------------------------------------------------------------- /7zip-log-to-file.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 7za a $1 "${2}" "${3}" > "${4}" 2>&1 3 | if [ $? -eq 0 ]; then 4 | 5 | rm -f "${4}" 6 | 7 | fi 8 | 9 | -------------------------------------------------------------------------------- /cron.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "" 3 | 4 | ## Script name 5 | SCRIPT_NAME="zzmysqldump" 6 | 7 | bash "/usr/local/turbolab.it/zzmysqldump/zzmysqldump.sh" > "${MYSQL_BACKUP_DIR}automatic-backup.log" 2>&1 8 | -------------------------------------------------------------------------------- /cron: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | PATH=/sbin:/bin:/usr/sbin:/usr/bin 3 | 4 | ## Dump every database, every night 5 | 0 3 * * * root bash "/usr/local/turbolab.it/zzmysqldump/cron.sh" > /dev/null 2>&1 6 | 7 | 8 | ## 👇🏻 If the last entry is missing a newline, cron will consider it broken and refuse to run it 👇🏻 9 | 10 | -------------------------------------------------------------------------------- /zzmysqldump.default.conf: -------------------------------------------------------------------------------- 1 | MYSQL_USER="root" 2 | MYSQL_PASSWORD="123456" 3 | MYSQL_HOST="localhost" 4 | MYSQL_DB_EXCLUDE="information_schema|performance_schema|sys" 5 | MYSQL_DB_INCLUDE="" 6 | MYSQLDUMP_SKIP_TRIGGERS=0 7 | MYSQLDUMP_OPTIONS="--opt --add-drop-database --lock-all-tables --routines --force" 8 | MYSQL_BACKUP_DIR="${HOME}/backup/mysql/" 9 | SEVENZIP_COMPRESS_OPTIONS="-t7z -mx=9 -mfb=64 -md=64m -sdel" 10 | SEVENZIP_NON_BLOCKING=1 11 | RETENTION_DAYS=6 12 | 13 | ## If the compression is too slow, try this: 14 | # SEVENZIP_COMPRESS_OPTIONS="-t7z -mx=3 -mfb=16 -md=16m -sdel" 15 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "" 3 | SCRIPT_NAME=zzmysqldump 4 | 5 | ## bash-fx 6 | if [ -z $(command -v curl) ]; then sudo apt update && sudo apt install curl -y; fi 7 | curl -s https://raw.githubusercontent.com/TurboLabIt/bash-fx/master/setup.sh?$(date +%s) | sudo bash 8 | source /usr/local/turbolab.it/bash-fx/bash-fx.sh 9 | ## bash-fx is ready 10 | 11 | sudo bash /usr/local/turbolab.it/bash-fx/setup/start.sh ${SCRIPT_NAME} 12 | sudo apt install git mysql-client p7zip-full -y 13 | fxLinkBin ${INSTALL_DIR}${SCRIPT_NAME}.sh 14 | fxLinkBin ${INSTALL_DIR}zzmysqlimp.sh 15 | 16 | if [ ! -f "/etc/cron.d/zzmysqldump" ]; then 17 | sudo cp "${INSTALL_DIR}cron" "/etc/cron.d/zzmysqldump" 18 | fi 19 | 20 | sudo bash /usr/local/turbolab.it/bash-fx/setup/the-end.sh ${SCRIPT_NAME} 21 | -------------------------------------------------------------------------------- /zzmysqlclean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "" 3 | 4 | ## Script name 5 | SCRIPT_NAME=zzmysqlclean 6 | 7 | source "/usr/local/turbolab.it/zzmysqldump/base.sh" 8 | 9 | ## Parameter validation 10 | if [ -z "$1" ]; then 11 | 12 | echo "" 13 | echo "vvvvvvvvvvvvvvvvvvvv" 14 | echo "Catastrophic error!!" 15 | echo "^^^^^^^^^^^^^^^^^^^^" 16 | echo "You MUST provide the name of the database to clean as the first argument" 17 | echo "" 18 | exit 19 | 20 | fi 21 | 22 | DATABASE_NAME="$1" 23 | 24 | ## Retrive databases list and test connection 25 | listDatabases 26 | 27 | 28 | TABLES=$(mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" --skip-column-names --silent -e 'show tables' "$DATABASE_NAME" | tail -n +1) 29 | 30 | echo "" 31 | echo "Cleaning" 32 | echo "---------" 33 | while IFS= read -r line; do 34 | 35 | if [ "$line" != "migration_versions" ]; then 36 | 37 | echo "->Table: $line" 38 | mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $line" "$DATABASE_NAME" 39 | echo "" 40 | 41 | fi 42 | 43 | done <<< "$TABLES" 44 | 45 | zzmysqldumpPrintEndFooter 46 | 47 | -------------------------------------------------------------------------------- /zzmysqlimp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ## bash-fx 4 | if [ -z $(command -v curl) ]; then sudo apt update && sudo apt install curl -y; fi 5 | if [ -f "/usr/local/turbolab.it/bash-fx/bash-fx.sh" ]; then 6 | source "/usr/local/turbolab.it/bash-fx/bash-fx.sh" 7 | else 8 | source <(curl -s https://raw.githubusercontent.com/TurboLabIt/bash-fx/main/bash-fx.sh) 9 | fi 10 | ## bash-fx is ready 11 | 12 | fxHeader "↖ zzmysqlimp" 13 | 14 | fxConfigLoader 15 | 16 | 17 | ## Checking input file 18 | DUMP_FULLPATH=$(readlink -f "$1") 19 | if [ -z "$DUMP_FULLPATH" ] || [ ! -f "$DUMP_FULLPATH" ]; then 20 | 21 | fxCatastrophicError "Dump to import not found! 22 | 🕳 $DUMP_FULLPATH 23 | " 24 | fi 25 | 26 | 27 | fxTitle "Extracting..." 28 | DUMP_DIR=$(dirname "$DUMP_FULLPATH")/ 29 | DUMPFILE_FULLPATH=${DUMP_FULLPATH%.7z} 30 | 31 | echo "Directory: ##${DUMP_DIR}##" 32 | echo "Filename: ##${DUMPFILE_FULLPATH}##" 33 | 34 | if [ ! -f "$DUMPFILE_FULLPATH" ] || [ "$(find "$DUMPFILE_FULLPATH" -mmin +3600)" ]; then 35 | 7za e "${1}" -o"${DUMP_DIR}" -y 36 | else 37 | fxInfo "The extracted file exists and was created today. Skipping the un-7zipping!" 38 | fi 39 | 40 | fxTitle "Listing..." 41 | ls -lh "${DUMP_DIR}" | grep $(basename ${DUMPFILE_FULLPATH}) 42 | 43 | 44 | fxTitle "Changing database name..." 45 | 46 | function sedReplace() 47 | { 48 | sed -i "s|${REPLACE_REGEX}|${REPLACE_WITH_TEXT}|g" "${DUMPFILE_FULLPATH}" --regexp-extended 49 | fxOK "Done" 50 | } 51 | 52 | if [ ! -z "$2" ]; then 53 | 54 | fxInfo "OK, the new database name will be #$2#" 55 | echo "" 56 | 57 | REPLACE_REGEX='^-- Current Database: `.+`' 58 | REPLACE_WITH_TEXT="-- Database renamed to ##$2## with https://github.com/TurboLabIt/zzmysqldump" 59 | sed -i "s|${REPLACE_REGEX}|&\n${REPLACE_WITH_TEXT}|g" "${DUMPFILE_FULLPATH}" --regexp-extended 60 | fxOK "Note added" 61 | 62 | REPLACE_REGEX='^/\*!40000 DROP DATABASE IF EXISTS `.+`\*/;' 63 | REPLACE_WITH_TEXT="/\\*!40000 DROP DATABASE IF EXISTS \`$2\`\\*/;" 64 | sedReplace "$REPLACE_REGEX" "$REPLACE_WITH_TEXT" 65 | 66 | REPLACE_REGEX='^CREATE DATABASE /\*!32312 IF NOT EXISTS\*/ `.+`' 67 | REPLACE_WITH_TEXT="CREATE DATABASE /\\*!32312 IF NOT EXISTS\\*/ \`$2\`" 68 | sedReplace "$REPLACE_REGEX" "$REPLACE_WITH_TEXT" 69 | 70 | REPLACE_REGEX='^USE `.+`;' 71 | REPLACE_WITH_TEXT="USE \`$2\`;" 72 | sedReplace "$REPLACE_REGEX" "$REPLACE_WITH_TEXT" 73 | 74 | else 75 | 76 | fxInfo "New database name not provided. Using the same name provided by the dump" 77 | fi 78 | 79 | 80 | fxTitle "Importing the extracted dump..." 81 | mysql -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" < "$DUMPFILE_FULLPATH" 82 | 83 | 84 | fxEndFooter 85 | -------------------------------------------------------------------------------- /zzmysqldump.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ## bash-fx 4 | if [ -z $(command -v curl) ]; then sudo apt update && sudo apt install curl -y; fi 5 | if [ -f "/usr/local/turbolab.it/bash-fx/bash-fx.sh" ]; then 6 | source "/usr/local/turbolab.it/bash-fx/bash-fx.sh" 7 | else 8 | source <(curl -s https://raw.githubusercontent.com/TurboLabIt/bash-fx/main/bash-fx.sh) 9 | fi 10 | ## bash-fx is ready 11 | 12 | fxHeader "📦 zzmysqldump" 13 | 14 | fxConfigLoader "$1" 15 | 16 | 17 | fxTitle "🔌 Connecting..." 18 | if [ ! -z "$MYSQL_PASSWORD" ]; then 19 | MYSQL_PASSWORD_HIDDEN="${MYSQL_PASSWORD:0:2}**...**${MYSQL_PASSWORD: -2}" 20 | fi 21 | 22 | echo "👤 User: ##${MYSQL_USER}##" 23 | echo "🔑 Pass: ##${MYSQL_PASSWORD_HIDDEN}##" 24 | echo "🖥️ Host: ##${MYSQL_HOST}##" 25 | echo "" 26 | 27 | DATABASES=$(mysql -N -u "${MYSQL_USER}" -p"${MYSQL_PASSWORD}" -h "${MYSQL_HOST}" -e 'show databases') 28 | if [ $? -eq 0 ]; then 29 | fxMessage "$DATABASES" 30 | else 31 | fxCatastrophicError "Database connection failed" 32 | fi 33 | 34 | 35 | fxTitle "📂 Creating the backup directory..." 36 | MYSQL_BACKUP_DIR="${MYSQL_BACKUP_DIR%/}/" 37 | fxInfo "The backup directory is ##${MYSQL_BACKUP_DIR}##" 38 | mkdir -p "${MYSQL_BACKUP_DIR}" 39 | touch "${MYSQL_BACKUP_DIR}⚠️ WARNING! This folder is auto-cleaned periodically!" 40 | 41 | 42 | fxTitle "🚫 Applying exclude filter..." 43 | if [ ! -z "$MYSQL_DB_EXCLUDE" ]; then 44 | 45 | DATABASES=$(echo "$DATABASES" | egrep -vx "$MYSQL_DB_EXCLUDE") 46 | fxMessage "$DATABASES" 47 | 48 | else 49 | 50 | fxInfo "No exclude filter defined. I'm going to backup every database" 51 | fi 52 | 53 | 54 | fxTitle "💚 Applying include filter.." 55 | if [ ! -z "$MYSQL_DB_INCLUDE" ]; then 56 | 57 | DATABASES=$(echo "$DATABASES" | egrep -x "$MYSQL_DB_INCLUDE") 58 | fxMessage "$DATABASES" 59 | 60 | else 61 | 62 | fxInfo "No include filter defined." 63 | fi 64 | 65 | 66 | ## Set and clean the 7zip log for non-blocking mode 67 | fxTitle "💨 Check if 7-Zip should run in non-blocking mode..." 68 | if [ "${SEVENZIP_NON_BLOCKING}" = 1 ]; then 69 | 70 | fxMessage "7-Zip NON-BLOCKING mode enabled" 71 | SEVENZIP_NON_BLOCKING_LOGFILE_SUFFIX=_background_7zipping.log 72 | ## remove leftovers 73 | rm -f "${MYSQL_BACKUP_DIR}"*${SEVENZIP_NON_BLOCKING_LOGFILE_SUFFIX} 74 | 75 | else 76 | 77 | fxInfo "7-Zip will run is blocking mode" 78 | fi 79 | 80 | 81 | fxTitle "🔫 Include/exclude triggers..." 82 | if [ "${MYSQLDUMP_SKIP_TRIGGERS}" = 1 ]; then 83 | 84 | fxWarning "Triggers skipping is enabled. Your dump WON'T contain any trigger" 85 | MYSQLDUMP_SKIP_TRIGGERS_CLI_OPTION="--skip-triggers" 86 | 87 | else 88 | 89 | fxOK "Triggers will be included in your dump" 90 | fi 91 | 92 | 93 | ## Iterate over DBs 94 | for DATABASE in $DATABASES; do 95 | 96 | DOWEEK="$(date +'%u')" 97 | 98 | ## Dump filename 99 | DUMPFILE_FULLPATH=${MYSQL_BACKUP_DIR}${HOSTNAME}_${DATABASE}_${DOWEEK}.sql 100 | 101 | fxTitle "📦 mysqldumping ##${DATABASE}##" 102 | fxMessage "$DUMPFILE_FULLPATH" 103 | mysqldump \ 104 | -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" -h "$MYSQL_HOST" \ 105 | $MYSQLDUMP_OPTIONS $MYSQLDUMP_SKIP_TRIGGERS_CLI_OPTION \ 106 | --databases "$DATABASE" > "$DUMPFILE_FULLPATH" 107 | 108 | fxTitle "🧪 Optimizing the exported file..." 109 | ## autocommit optimization - header 110 | NO_AUTOCOMMIT_TEXT="SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, AUTOCOMMIT=0;" 111 | sed -i "/Server version/ a ${NO_AUTOCOMMIT_TEXT}" "$DUMPFILE_FULLPATH" 112 | ## autocommit optimization - footer 113 | echo "COMMIT;" >> "$DUMPFILE_FULLPATH" 114 | echo "SET AUTOCOMMIT=@OLD_AUTOCOMMIT" >> "$DUMPFILE_FULLPATH" 115 | 116 | fxTitle "🗜 7-zipping ##${DATABASE}##" 117 | rm -f "${DUMPFILE_FULLPATH}.7z" 118 | 119 | if [ ${SEVENZIP_NON_BLOCKING} == 1 ]; then 120 | bash "${SCRIPT_DIR}7zip-log-to-file.sh" "${SEVENZIP_COMPRESS_OPTIONS}" "${DUMPFILE_FULLPATH}.7z" "${DUMPFILE_FULLPATH}" "${DUMPFILE_FULLPATH}${SEVENZIP_NON_BLOCKING_LOGFILE_SUFFIX}" & 121 | else 122 | 7za a ${SEVENZIP_COMPRESS_OPTIONS} "${DUMPFILE_FULLPATH}.7z" "${DUMPFILE_FULLPATH}" 123 | fi 124 | 125 | done 126 | 127 | 128 | fxTitle "Deleting old files..." 129 | if [ -z "$1" ]; then 130 | 131 | fxMessage "Current retention: ##${RETENTION_DAYS}## day(s)" 132 | find "${MYSQL_BACKUP_DIR}" -type f -mtime +${RETENTION_DAYS} \( -name "*.sql.7z" -o -name "*.sql" -o -name "*.log" \) 133 | find "${MYSQL_BACKUP_DIR}" -type f -mtime +${RETENTION_DAYS} \( -name "*.sql.7z" -o -name "*.sql" -o -name "*.log" \) -delete 134 | 135 | else 136 | 137 | fxInfo "Skipping when running with a profile" 138 | fi 139 | 140 | 141 | fxTitle "Backup file list" 142 | ls -latrh "${MYSQL_BACKUP_DIR}" 143 | 144 | 145 | fxEndFooter 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zzmysqldump 2 | 3 | mysqldump every DB of your MySQL Server to its own, 7z-compressed file. The provided `setup.sh` auto-installs/updates the code and makes the script available as a new, simple shell command (`zzmysqldump`). The project aims to deliver a fully configfile-driven script: no code editing should be necessary! 4 | 5 | **Parli italiano?** » Leggi: [MySQL/mysqldump: creare un file distinto/singolo per ogni database con zzmysqldump (script)](https://turbolab.it/server-1224/mysql-mysqldump-creare-file-distinto-singolo-ogni-database-zzmysqldump-script-1311) 6 | 7 | ![logo](https://turbolab.it/immagini/max/mysql-mysqldump-creare-file-distinto-singolo-ogni-database-zzmysqldump-script-zzmysqldump-spotlight-8837.img) 8 | 9 | 10 | # Install 11 | 12 | Just execute: 13 | 14 | ````bash 15 | sudo apt install curl -y && curl -s https://raw.githubusercontent.com/TurboLabIt/zzmysqldump/master/setup.sh?$(date +%s) | sudo bash 16 | 17 | ```` 18 | 19 | Now copy the provided sample configuration file (`zzmysqldump.default.conf`) to your own `zzmysqldump.conf` and replace username, password and stuff: 20 | 21 | 🤓 You don't need to set the `MYSQL_` vars to `root` if `/etc/turbolab.it/mysql.conf` exists! Pro tip: if you set the server up with [webstack](https://github.com/TurboLabIt/webstackup), the file was generated automatically. Just make sure you have the permission to read it, or run zzmysqldump as sudo. 22 | 23 | ````bash 24 | sudo cp /usr/local/turbolab.it/zzmysqldump/zzmysqldump.default.conf /etc/turbolab.it/zzmysqldump.conf && sudo nano /etc/turbolab.it/zzmysqldump.conf 25 | 26 | ```` 27 | 28 | 29 | # Run it 30 | 31 | It's MySQL Server backup time! Run `zzmysqldump` to generate your 7z-compressed, database-dump files. 32 | 33 | 34 | # Import 35 | 36 | Import a dump 37 | 38 | 39 | ````shell 40 | zzmysqldump mydump.sql.7z 41 | 42 | ```` 43 | 44 | 45 | Import a dump but change the imported database name: 46 | 47 | 48 | ````shell 49 | zzmysqldump mydump.sql.7z new-database-name 50 | 51 | ```` 52 | 53 | 54 | # Known issues (which are not features, for real) 55 | 56 | -> `mysqldump: Couldn't execute 'FLUSH TABLES': Access denied; you need (at least one of) the RELOAD privilege(s) for this operation (1227)` 57 | 58 | Some extra privileges are needed for the `--lock-all-tables` mysqldump argument activated by the default configuration. root has it, other users don't. 59 | 60 | As root, grant it: `GRANT RELOAD, PROCESS ON *.* TO 'your_user'@'127.0.0.1'` (some of these can only be granted globally, not to a particular database). 61 | 62 | If you can't grant the RELOAD privilege to your user and you are in a dev/low-traffic enviroment, you can just remove `--lock-all-tables` in your config. For example, just leave `MYSQLDUMP_OPTIONS="--opt --add-drop-database"` 63 | 64 | -> `7-zipping` fails. `Error: Incorrect command line` 65 | 66 | Your 7za package is ancient! It's failing due to the `-sdel` argument, introduced by 7-zip 9.30 alpha (2012-10-26). You can just remove this argument in your config. For example, just leave `SEVENZIP_COMPRESS_OPTIONS="-t7z -mx=9 -mfb=256 -md=256m -ms=on"` 67 | 68 | 69 | # Database compression: test and results 70 | 71 | The 7-zip compression is done with a command like this: 72 | 73 | `7za a -t7z -mx=9 -mfb=256 -md=256m db-dump.sql.7z db-dump.sql` 74 | 75 | [man 7za](https://linux.die.net/man/1/7za). 76 | 77 | I run a test against some real life db dumps to find the best compression options for this specific use case. 78 | 79 | ```` 80 | clear 81 | TIME_START="$(date +%s)" 82 | 7za a -t7z -mx=9 -mfb=256 -md=128m "db_contenuti_tli.sql -t7z -mx=9 -mfb=256 -md=128m.7z" db_contenuti_tli.sql 83 | 7za a -t7z -mx=9 -mfb=256 -md=128m "db_ecommerce_mobili.sql -t7z -mx=9 -mfb=256 -md=128m.7z" db_ecommerce_mobili.sql 84 | 7za a -t7z -mx=9 -mfb=256 -md=128m "db_ecommerce_turismo.sql -t7z -mx=9 -mfb=256 -md=128m.7z" db_ecommerce_turismo.sql 85 | 7za a -t7z -mx=9 -mfb=256 -md=128m "db_forum.sql -t7z -mx=9 -mfb=256 -md=128m.7z" db_forum.sql 86 | 7za a -t7z -mx=9 -mfb=256 -md=128m "db_wordpress.sql -t7z -mx=9 -mfb=256 -md=128m.7z" db_wordpress.sql 87 | echo "$((($(date +%s)-$TIME_START)/60)) min." 88 | ## 19 min. 89 | 90 | TIME_START="$(date +%s)" 91 | 7za a -t7z -mx=9 -mfb=128 -md=128m "db_contenuti_tli.sql -t7z -mx=9 -mfb=128 -md=128m.7z" db_contenuti_tli.sql 92 | 7za a -t7z -mx=9 -mfb=128 -md=128m "db_ecommerce_mobili.sql -t7z -mx=9 -mfb=128 -md=128m.7z" db_ecommerce_mobili.sql 93 | 7za a -t7z -mx=9 -mfb=128 -md=128m "db_ecommerce_turismo.sql -t7z -mx=9 -mfb=128 -md=128m.7z" db_ecommerce_turismo.sql 94 | 7za a -t7z -mx=9 -mfb=128 -md=128m "db_forum.sql -t7z -mx=9 -mfb=128 -md=128m.7z" db_forum.sql 95 | 7za a -t7z -mx=9 -mfb=128 -md=128m "db_wordpress.sql -t7z -mx=9 -mfb=128 -md=128m.7z" db_wordpress.sql 96 | echo "$((($(date +%s)-$TIME_START)/60)) min." 97 | ## 12 min. 98 | 99 | TIME_START="$(date +%s)" 100 | 7za a -t7z -mx=9 -mfb=64 -md=128m "db_contenuti_tli.sql -t7z -mx=9 -mfb=64 -md=128m.7z" db_contenuti_tli.sql 101 | 7za a -t7z -mx=9 -mfb=64 -md=128m "db_ecommerce_mobili.sql -t7z -mx=9 -mfb=64 -md=128m.7z" db_ecommerce_mobili.sql 102 | 7za a -t7z -mx=9 -mfb=64 -md=128m "db_ecommerce_turismo.sql -t7z -mx=9 -mfb=64 -md=128m.7z" db_ecommerce_turismo.sql 103 | 7za a -t7z -mx=9 -mfb=64 -md=128m "db_forum.sql -t7z -mx=9 -mfb=64 -md=128m.7z" db_forum.sql 104 | 7za a -t7z -mx=9 -mfb=64 -md=128m "db_wordpress.sql -t7z -mx=9 -mfb=64 -md=128m.7z" db_wordpress.sql 105 | echo "$((($(date +%s)-$TIME_START)/60)) min." 106 | ## 8 min. 107 | 108 | TIME_START="$(date +%s)" 109 | 7za a -t7z -mx=9 -mfb=128 -md=64m "db_contenuti_tli.sql -t7z -mx=9 -mfb=128 -md=64m.7z" db_contenuti_tli.sql 110 | 7za a -t7z -mx=9 -mfb=128 -md=64m "db_ecommerce_mobili.sql -t7z -mx=9 -mfb=128 -md=64m.7z" db_ecommerce_mobili.sql 111 | 7za a -t7z -mx=9 -mfb=128 -md=64m "db_ecommerce_turismo.sql -t7z -mx=9 -mfb=128 -md=64m.7z" db_ecommerce_turismo.sql 112 | 7za a -t7z -mx=9 -mfb=128 -md=64m "db_forum.sql -t7z -mx=9 -mfb=128 -md=64m.7z" db_forum.sql 113 | 7za a -t7z -mx=9 -mfb=128 -md=64m "db_wordpress.sql -t7z -mx=9 -mfb=128 -md=64m.7z" db_wordpress.sql 114 | echo "$((($(date +%s)-$TIME_START)/60)) min." 115 | ## 11 min. 116 | 117 | TIME_START="$(date +%s)" 118 | 7za a -t7z -mx=9 -mfb=64 -md=64m "db_contenuti_tli.sql -t7z -mx=9 -mfb=64 -md=64m.7z" db_contenuti_tli.sql 119 | 7za a -t7z -mx=9 -mfb=64 -md=64m "db_ecommerce_mobili.sql -t7z -mx=9 -mfb=64 -md=64m.7z" db_ecommerce_mobili.sql 120 | 7za a -t7z -mx=9 -mfb=64 -md=64m "db_ecommerce_turismo.sql -t7z -mx=9 -mfb=64 -md=64m.7z" db_ecommerce_turismo.sql 121 | 7za a -t7z -mx=9 -mfb=64 -md=64m "db_forum.sql -t7z -mx=9 -mfb=64 -md=64m.7z" db_forum.sql 122 | 7za a -t7z -mx=9 -mfb=64 -md=64m "db_wordpress.sql -t7z -mx=9 -mfb=64 -md=64m.7z" db_wordpress.sql 123 | echo "$((($(date +%s)-$TIME_START)/60)) min." 124 | ## 8 min. 125 | ```` 126 | 127 | These options triggered the OoM-Killer midway through the 3,5G dump compression on my PC with 16 GB of RAM: 128 | 129 | - `-mfb=256 -md=256m` 130 | - `-mfb=128 -md=256m` 131 | 132 | Results: 133 | 134 | ```` 135 | exa -lh --color=always --no-user --no-time --no-permissions 136 | 137 | 35M db_contenuti_tli.sql 138 | 5,2M db_contenuti_tli.sql -t7z -mx=9 -mfb=64 -md=64m.7z 139 | 5,2M db_contenuti_tli.sql -t7z -mx=9 -mfb=64 -md=128m.7z 140 | 5,1M db_contenuti_tli.sql -t7z -mx=9 -mfb=128 -md=64m.7z 141 | 5,1M db_contenuti_tli.sql -t7z -mx=9 -mfb=128 -md=128m.7z 142 | 5,1M db_contenuti_tli.sql -t7z -mx=9 -mfb=256 -md=128m.7z 143 | 3,5G db_ecommerce_mobili.sql 144 | 140M db_ecommerce_mobili.sql -t7z -mx=9 -mfb=64 -md=64m.7z 145 | 140M db_ecommerce_mobili.sql -t7z -mx=9 -mfb=64 -md=128m.7z 146 | 134M db_ecommerce_mobili.sql -t7z -mx=9 -mfb=128 -md=64m.7z 147 | 134M db_ecommerce_mobili.sql -t7z -mx=9 -mfb=128 -md=128m.7z 148 | 132M db_ecommerce_mobili.sql -t7z -mx=9 -mfb=256 -md=128m.7z 149 | 3,7G db_ecommerce_turismo.sql 150 | 670M db_ecommerce_turismo.sql -t7z -mx=9 -mfb=64 -md=64m.7z 151 | 662M db_ecommerce_turismo.sql -t7z -mx=9 -mfb=64 -md=128m.7z 152 | 668M db_ecommerce_turismo.sql -t7z -mx=9 -mfb=128 -md=64m.7z 153 | 660M db_ecommerce_turismo.sql -t7z -mx=9 -mfb=128 -md=128m.7z 154 | 657M db_ecommerce_turismo.sql -t7z -mx=9 -mfb=256 -md=128m.7z 155 | 183M db_forum.sql 156 | 28M db_forum.sql -t7z -mx=9 -mfb=64 -md=64m.7z 157 | 28M db_forum.sql -t7z -mx=9 -mfb=64 -md=128m.7z 158 | 27M db_forum.sql -t7z -mx=9 -mfb=128 -md=64m.7z 159 | 27M db_forum.sql -t7z -mx=9 -mfb=128 -md=128m.7z 160 | 27M db_forum.sql -t7z -mx=9 -mfb=256 -md=128m.7z 161 | 34M db_wordpress.sql 162 | 1,4M db_wordpress.sql -t7z -mx=9 -mfb=64 -md=64m.7z 163 | 1,4M db_wordpress.sql -t7z -mx=9 -mfb=64 -md=128m.7z 164 | 1,3M db_wordpress.sql -t7z -mx=9 -mfb=128 -md=64m.7z 165 | 1,3M db_wordpress.sql -t7z -mx=9 -mfb=128 -md=128m.7z 166 | 1,3M db_wordpress.sql -t7z -mx=9 -mfb=256 -md=128m.7z 167 | ```` 168 | 169 | Takeaways: 170 | 171 | - the ratio difference is not significant 172 | - the speed difference is huge 173 | 174 | I chose `-mfb=64 -md=64m` as a default just because is the fastest. `-mx=9 -mfb=64 -md=128m` took more or less the same time, but only in one case it gave better result. So I went with 64/64m, just because it uses less RAM. 175 | --------------------------------------------------------------------------------