Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
linux:postgresql [24-09-2018 16:27] edmc73 [Base] |
linux:postgresql [16-10-2018 15:04] edmc73 [Backup] |
||
---|---|---|---|
Ligne 149: | Ligne 149: | ||
| | ||
===== Backup ===== | ===== Backup ===== | ||
+ | |||
+ | |||
+ | # dump to single SQL file | ||
+ | $ pg_dump -d mydb -n public -f mydb.sql | ||
+ | |||
+ | # dump to a custom format file | ||
+ | $ pg_dump -d mydb -n public -Fc -f mydb.pgdmp | ||
+ | |||
+ | |||
+ | # restoring from a SQL dump file, the simple version | ||
+ | $ psql -d mydb_new < mydb.sql | ||
+ | |||
+ | # restoring from a SQL dump file, the recommended version | ||
+ | $ PGOPTIONS=' | ||
+ | |||
+ | # restoring from a dump written to a custom format file | ||
+ | $ pg_restore -d mydb_new -v -1 mydb.pgdmp | ||
+ | |||
+ | # restore a single table from the dump | ||
+ | $ pg_restore -d mydb_new --table=mytable -v -1 mydb.pgdmp | ||
+ | |||
+ | # restore a single function from the dump | ||
+ | $ pg_restore -d mydb_new --function=myfunc -v -1 mydb.pgdmp | ||
+ | |||
+ | |||
+ | --- https:// | ||
+ | |||
+ | |||
+ | Option de pg_restore | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | |||
Backup: (-Fc est un format compressé qui prend donc moins de place) | Backup: (-Fc est un format compressé qui prend donc moins de place) | ||
Ligne 172: | Ligne 214: | ||
$ pg_dump --table products -U geekstuff article -f onlytable.sql | $ pg_dump --table products -U geekstuff article -f onlytable.sql | ||
$ pg_dump --table products -U geekstuff article -Fc -f onlytable.backup | $ pg_dump --table products -U geekstuff article -Fc -f onlytable.backup | ||
+ | |||
+ | |||
+ | Autre facon de faire un backup sous forme de fichier | ||
+ | |||
+ | pg_dump -Fd -f dbName_objects -j 10 -t ' | ||
+ | |||
+ | Cette commande utilise '' | ||
+ | '' | ||
+ | '' | ||
+ | '' | ||
+ | |||
+ | L' | ||
+ | |||
+ | Utilisez la commande suivante pour voir la correspondance | ||
+ | |||
+ | pg_restore --list -Fd dbName_objects/ | ||
+ | |||
+ | in order to have each file not compressed (in raw SQL) | ||
+ | |||
+ | pg_dump --data-only --compress=0 --format=directory --file=dbName_objects --jobs=10 --table=' | ||
+ | | ||
+ | Sinon un script bash qui boucle sur la liste des tables | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | # Config: | ||
+ | DB=rezopilotdatabase | ||
+ | U=postgres | ||
+ | # tablename searchpattern, | ||
+ | P="" | ||
+ | # directory to dump files without trailing slash: | ||
+ | DIR=~/ | ||
+ | |||
+ | mkdir -p $DIR | ||
+ | TABLES=" | ||
+ | information_schema.tables WHERE table_type=' | ||
+ | LIKE ' | ||
+ | for table in $TABLES; do | ||
+ | echo backup $table ... | ||
+ | pg_dump $DB -U $U -w -t $table > $DIR/ | ||
+ | done; | ||
+ | echo done | ||
+ | </ | ||
+ | |||
===== pg_dump to mysql ===== | ===== pg_dump to mysql ===== |