Projekt

Allgemein

Profil

Postgresql91 » Historie » Version 1

Jeremias Keihsler, 12.01.2017 14:45

1 1 Jeremias Keihsler
h1. PostgreSQL Disaster Recovery
2
3
h2. Backup (Exporting DB)
4
5
h3. Requirements
6
7
h3. Preliminary Note
8
9
The PostgreSQL-Database-Cluster is saved periodically in background by @rsnapshot@ and the @backup_psql.sh@-script.
10
11
The backup is located in @/var/cache/rsnapshot/@ where several subdirectories exist.
12
<pre><code class="bash">
13
cd /var/cache/rsnapshot
14
ls
15
</code></pre>
16
will give you an output like
17
<pre><code class="bash">
18
daily.0   hourly.10  hourly.14  hourly.18  hourly.21  hourly.4  hourly.8
19
daily.1   hourly.11  hourly.15  hourly.19  hourly.22  hourly.5  hourly.9
20
hourly.0  hourly.12  hourly.16  hourly.2   hourly.23  hourly.6
21
hourly.1  hourly.13  hourly.17  hourly.20  hourly.3   hourly.7
22
</code></pre>
23
@hourly.0@ is the most recent hourly backup, while @hourly.1@ is one hour before @hourly.0@ and so on. Once a day @hourly.23@ is copied to @daily.0@ and the former @daily.0@ is moved to @daily.1@ and so on.
24
25
if you want to save just the most recent backup go for @hourly.0@. The following example shows how to retrieve the backup with PSFTP [[vbip:software:remoteaccess|Remote Access for Windows machines]]
26
27
# find out what your local working directory is
28
# open connection to server in this example @192.168.2.167@
29
## if you connect to the server the first time, you can check the fingerprint and continue by storing the fingerprint locally by answering @y@
30
## *or* by not storing the fingerprint and answering @n@
31
## *or* pressing @<enter>@ if you don't trust this server
32
## login as: @root@
33
## provide your password
34
# change to the remote @rsnapshot@ directory
35
# change to the database-backup directory
36
# list the files
37
# download all files
38
## pg_dumpall.sql
39
## pg_hba.conf
40
## pg_ident.conf
41
## postgresql.conf
42
# close connection
43
# close terminal
44
45
<pre><code class="bash">
46
lpwd
47
open 192.168.2.167
48
cd /var/cache/rsnapshot/hourly.0
49
cd localhost/postgres
50
ls
51
get pg_dumpall.sql
52
get pg_hba.conf
53
get pg_ident.conf
54
get postgresql.conf
55
close
56
bye
57
</code></pre>
58
59
h2. Restore (Importing DB)
60
61
Importing the complete DB involves
62
* upload the DB-dump
63
* drop the current DB
64
* reloading a complete DB-dump
65
66
The following example shows how to retrieve the backup with PSFTP [[vbip:software:remoteaccess|Remote Access for Windows machines]]
67
68
# find out what your local working directory is
69
# change your local working directory to the local directory containing the @pg_dumpall.sql@ file
70
# open connection to server in this example @192.168.2.167@
71
## if you connect to the server the first time, you can check the fingerprint and continue by storing the fingerprint locally by answering @y@
72
## *or* by not storing the fingerprint and answering @n@
73
## *or* pressing @<enter>@ if you don't trust this server
74
## login as: @root@
75
## provide your password
76
# change to the remote @postgres-data@ directory
77
# upload the dump file
78
## pg_dumpall.sql
79
# close connection
80
# close terminal
81
82
<pre><code class="bash">
83
lpwd
84
lcd c:\psql.bak\
85
open 192.168.2.167
86
cd /var/lib/pgsql/9.1/data
87
88
put pg_dumpall.sql
89
close
90
bye
91
</code></pre>
92
93
if applicable drop the expired current database via remote shell
94
<pre><code class="bash">
95
cd /var/lib/pgsql/9.1/data
96
su postgres
97
dropdb JANUS_11002
98
exit
99
</code></pre>
100
101
restore the dump
102
<pre><code class="bash">
103
cd /var/lib/pgsql/9.1/data
104
chown postgres:postgres pg_dumpall.sql
105
su postgres
106
psql -f pg_dumpall.sql postgres
107
</code></pre>