Grimoire-
Command
.es

GNU+Linux command memo

Dump database and restore

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

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

 

PostgreSQL
$ pg_dump -j $(nproc) $database_name | gzip > dump_file.gz (1)
$ createdb $database_name (2)
$ gunzip -c dump_file.gz | psql $database_name (3)
1 Backup, using as many job as available CPU
2 Create a restore destination database
3 Restore

 

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