Db-support » History » Version 8
Philippe May, 24/10/2018 11:44
1 | 1 | Philippe May | h1. Database |
---|---|---|---|
2 | 1 | Philippe May | |
3 | 3 | Philippe May | This documentation assumes that the Postgis package has been installed (see [[CSR_server#Database]]). |
4 | 3 | Philippe May | |
5 | 5 | Philippe May | h2. Configure the server |
6 | 5 | Philippe May | |
7 | 5 | Philippe May | h3. Allow connections from other hosts in the local network |
8 | 5 | Philippe May | |
9 | 5 | Philippe May | Add in @/etc/postgresql/9.6/main/pg_hba.conf@: |
10 | 5 | Philippe May | |
11 | 5 | Philippe May | <pre> |
12 | 5 | Philippe May | host all all 192.168.0.0/24 md5 |
13 | 5 | Philippe May | </pre> |
14 | 5 | Philippe May | |
15 | 3 | Philippe May | h2. Creation of the database |
16 | 4 | Philippe May | |
17 | 3 | Philippe May | As @postgres@ user: |
18 | 4 | Philippe May | |
19 | 5 | Philippe May | <pre> |
20 | 3 | Philippe May | createdb -E utf8 -T template0 avgis |
21 | 5 | Philippe May | </pre> |
22 | 1 | Philippe May | |
23 | 1 | Philippe May | h2. Backups |
24 | 1 | Philippe May | |
25 | 1 | Philippe May | h3. Primary |
26 | 1 | Philippe May | |
27 | 7 | Philippe May | The database is backed up every day at midnight. The dump file is located in @/var/backups/postgres/@. |
28 | 7 | Philippe May | |
29 | 8 | Philippe May | h3. Secondary |
30 | 8 | Philippe May | |
31 | 1 | Philippe May | There are other backups (daily, weekly, monthly) thanks to Debian package @autopostgresqlbackup@), located (default) in @/var/lib/autopostgresqlbackup@. |
32 | 1 | Philippe May | |
33 | 8 | Philippe May | h3. Tertiary (dom0) |
34 | 1 | Philippe May | |
35 | 1 | Philippe May | The whole virtual machine is backed up by BackupNinja on the "dom0" controller, using: |
36 | 1 | Philippe May | - rdiff backups every day |
37 | 1 | Philippe May | - tar files on Saturdays. |
38 | 1 | Philippe May | |
39 | 1 | Philippe May | See @/etc/backups.d@ on the dom0 (192.168.0.12). |
40 | 1 | Philippe May | |
41 | 8 | Philippe May | h3. Remote |
42 | 1 | Philippe May | |
43 | 1 | Philippe May | TODO: remote backup. |
44 | 1 | Philippe May | |
45 | 1 | Philippe May | |
46 | 1 | Philippe May | h2. Restoration |
47 | 1 | Philippe May | |
48 | 1 | Philippe May | If the VM is not shutdown properly, there's a chance that the database is corrupt, and needs to be restored from one of the backups. |
49 | 1 | Philippe May | |
50 | 1 | Philippe May | After the restoration, restart gisaf: |
51 | 1 | Philippe May | <pre> |
52 | 1 | Philippe May | systemctl restart uwsgi.service |
53 | 1 | Philippe May | </pre> |
54 | 1 | Philippe May | |
55 | 1 | Philippe May | h3. From primary backup |
56 | 1 | Philippe May | |
57 | 8 | Philippe May | *Note*: the roles aren't restored with this method. |
58 | 8 | Philippe May | |
59 | 1 | Philippe May | With user @postgres@: |
60 | 1 | Philippe May | <pre> |
61 | 2 | Philippe May | # Optionally, rename the corrupt database (selecting a name for a database like "avgis_c2")... |
62 | 1 | Philippe May | psql -c "ALTER DATABASE avgis RENAME TO avgis_c2;" |
63 | 2 | Philippe May | # ... or drop the existing database |
64 | 1 | Philippe May | psql -c "drop database avgis;" |
65 | 1 | Philippe May | # Create a new database: |
66 | 1 | Philippe May | createdb -E utf8 -T template0 avgis |
67 | 1 | Philippe May | # Restore the database |
68 | 1 | Philippe May | pg_restore -d avgis /var/backups/postgres/avgis.pg_dump |
69 | 8 | Philippe May | </pre> |
70 | 8 | Philippe May | |
71 | 8 | Philippe May | h3. From secondary backup |
72 | 8 | Philippe May | |
73 | 8 | Philippe May | @autopostgresqlbackup@ backs up the roles in @postgres_globals@. |
74 | 8 | Philippe May | |
75 | 8 | Philippe May | <pre> |
76 | 8 | Philippe May | zcat /var/lib/autopostgresqlbackup/daily/postgres_globals/postgres_globals_2018-10-24_06h25m.Wednesday.sql.gz | psql |
77 | 8 | Philippe May | zcat /var/lib/autopostgresqlbackup/daily/avgis/avgis_2018-10-24_06h25m.Wednesday.sql.gz | psql |
78 | 1 | Philippe May | </pre> |