Skip to content

Instantly share code, notes, and snippets.

@mupkoo
Last active October 24, 2022 09:26
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 mupkoo/8e7161113749ab8408c90c93e5219a42 to your computer and use it in GitHub Desktop.
Save mupkoo/8e7161113749ab8408c90c93e5219a42 to your computer and use it in GitHub Desktop.
PostgreSQL and MySQL - Dump all databases into separate files
for db in (mysql -u root -e "SHOW DATABASES WHERE `Database` NOT LIKE '%test%'" -s --skip-column-names);
mysqldump -u root --single-transaction (string trim $db) > (string trim $db).dump;
end
for db in (docker exec -i pg12 psql -U postgres -t -c "SELECT datname FROM pg_database WHERE datname NOT ILIKE '%_test%' AND datname NOT IN ('postgres', 'template0', 'template1')");
docker exec -i pg12 pg_dump (string trim $db) -U postgres --no-owner --no-acl --clean --create --if-exists -F custom > (string trim $db).dump;
end
for db in (psql -t -c "SELECT datname FROM pg_database WHERE datname NOT ILIKE '%_test%'");
pg_dump (string trim $db) --no-owner --no-acl --clean --create --if-exists -F custom > (string trim $db).dump;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment