Grimoire-
Command
.es

GNU+Linux command memo

Dump database and restore

Sauver une base de donnée dans un fichier et le restaurer

1. MySQL / MariaDB

$ mysqldump -u $user --password $dbname -r dump_file.sql (1)
$ mysql -u $user --password -e "source dump_file.sql" $database_name (2)
$ tar cJf dump_file.sql.tar.xz /var/lib/mysql/* (3)
1 To backup an live database
2 Restore from file
3 To backup a stopped database

2. PostgreSQL

$  pg_dump -h localhost -p 5433 -U $postgresql_role -W $database_name | gzip > file.gz (1)
$ createdb $database_name (2)
$ gunzip -c dump_file.gz | psql $database_name (3)
1 Backup
2 Create a restore destination database
3 Restore

3. SQLite3

$ cp db.sqlite3 dump_file.sqlite3 (1)
$ cp dump_file.sqlite3 db.sqlite3 (2)
1 Backup
2 Restore