Skip to content

Instantly share code, notes, and snippets.

@maoizm
Last active September 30, 2016 14:56
Show Gist options
  • Save maoizm/a8cfbad867149d5cb3a802a1bf7b1ab0 to your computer and use it in GitHub Desktop.
Save maoizm/a8cfbad867149d5cb3a802a1bf7b1ab0 to your computer and use it in GitHub Desktop.
Backs up Joomla database with correct SQL commands to restore on live system without rights to DROP tables and databases
#!/bin/bash
mysqldump -hHost -PportOfMYSQLserver -uUserName -pPassword DatabaseName --no-create-db --skip-add-drop-table | sed -r -e "s/CREATE TABLE (`[^`]+`)/CREATE TABLE IF NOT EXISTS \1/g" -e "s/LOCK TABLES (`[^`]+`)/DELETE FROM \1;\nLOCK TABLES \1/g" | gzip > "$(date +%Y%m%d_%H%M%S)_backup.sql.gz"
@maoizm
Copy link
Author

maoizm commented Sep 30, 2016

This is for sed in Windows command line

(double quotes used instead of single quotes in Linux environment)

mysqldump -h**hostOfMySQLserver** -P**portOfMySQLserver** -u**userName** -p**password** databaseName --no-create-db --skip-add-drop-table | sed -r -e "s/CREATE TABLE ([^`]+`)/CREATE TABLE IF NOT EXISTS \1/g" -e "s/LOCK TABLES (`[^`]+)/DELETE FROM \1;\nLOCK TABLES \1/g" | gzip > "$(date +%Y%m%d_%H%M%S)-**_databaseName_**.sql.gz"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment