1 |
1 |
2 .. _Additional Tips: |
2 .. _Additional Tips: |
3 |
3 |
4 Additional Tips |
4 Backups (mostly with postgresql) |
5 --------------- |
5 -------------------------------- |
6 |
6 |
7 Here are some additional tips as far as administration of a CubicWeb is concerned. |
7 It is always a good idea to backup. If your system does not do that, |
|
8 you should set it up. Note that whenever you do an upgrade, |
|
9 `cubicweb-ctl` offers you to backup your database. There are a number |
|
10 of ways for doing backups. |
8 |
11 |
9 Backup, backup, backup |
12 Using postgresql (and only that) |
10 `````````````````````` |
13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
11 |
14 |
12 It is always a good idea to backup. If your system does not do that, you should |
15 Before you |
13 set it up. Note that whenever you do an upgrade, `cubicweb-ctl` offers you to |
|
14 backup your database. There are a number of ways for doing backups. Before you |
|
15 go ahead, make sure the following permissions are correct :: |
16 go ahead, make sure the following permissions are correct :: |
16 |
17 |
17 # chgrp postgres /var/lib/cubicweb/backup |
18 # chgrp postgres /var/lib/cubicweb/backup |
18 |
|
19 # chmod g+ws /var/lib/cubicweb/backup |
19 # chmod g+ws /var/lib/cubicweb/backup |
20 |
|
21 # chgrp postgres /etc/cubicweb.d/*<instance>*/sources |
20 # chgrp postgres /etc/cubicweb.d/*<instance>*/sources |
22 |
|
23 # chmod g+r /etc/cubicweb.d/*<instance>*/sources |
21 # chmod g+r /etc/cubicweb.d/*<instance>*/sources |
24 |
|
25 **Classic way on PostgreSQL server** |
|
26 |
22 |
27 Simply use the pg_dump in a cron installed for `postgres` user on the database server:: |
23 Simply use the pg_dump in a cron installed for `postgres` user on the database server:: |
28 |
24 |
29 # m h dom mon dow command |
25 # m h dom mon dow command |
30 0 2 * * * pg_dump -Fc --username=cubicweb --no-owner <instance> > /var/backups/<instance>-$(date '+%Y-%m-%d_%H:%M:%S').dump |
26 0 2 * * * pg_dump -Fc --username=cubicweb --no-owner <instance> > /var/backups/<instance>-$(date '+%Y-%m-%d_%H:%M:%S').dump |
31 |
27 |
32 **CubicWeb way** |
28 Using :command:`cubicweb-ctl db-dump` |
|
29 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
33 |
30 |
34 The CubicWeb way is to use the `db-dump` command. For that, you have to put |
31 The CubicWeb way is to use the :command:`db-dump` command. For that, |
35 your passwords in a user-only-readable file at the home directory of root user. |
32 you have to put your passwords in a user-only-readable file at the |
36 The file is `.pgpass` (`chmod 0600`), in this case for a socket run connection |
33 home directory of root user. The file is `.pgpass` (`chmod 0600`), in |
37 to PostgreSQL :: |
34 this case for a socket run connection to PostgreSQL :: |
38 |
35 |
39 /var/run/postgresql:5432:<instance>:<database user>:<database password> |
36 /var/run/postgresql:5432:<instance>:<database user>:<database password> |
40 |
37 |
41 The postgres documentation for the `.pgpass` format can be found `here`_ |
38 The postgres documentation for the `.pgpass` format can be found `here`_ |
42 |
39 |
43 Then add the following command to the crontab of the user (`crontab -e`):: |
40 Then add the following command to the crontab of the user (`crontab -e`):: |
44 |
41 |
45 # m h dom mon dow command |
42 # m h dom mon dow command |
46 0 2 * * * cubicweb-ctl db-dump <instance> |
43 0 2 * * * cubicweb-ctl db-dump <instance> |
47 |
44 |
48 **The automated sysadmin way** |
45 |
|
46 Backup ninja |
|
47 ~~~~~~~~~~~~ |
49 |
48 |
50 You can use a combination `backup-ninja`_ (which has a postgres script in the |
49 You can use a combination `backup-ninja`_ (which has a postgres script in the |
51 example directory), `backuppc`)_ (for versionning). |
50 example directory), `backuppc`)_ (for versionning). |
52 |
51 |
53 Please note that in the *CubicWeb way* it adds a second location for your |
52 Please note that in the *CubicWeb way* it adds a second location for your |
54 password which is error-prone. |
53 password which is error-prone. |
55 |
54 |
56 .. _`here` : http://www.postgresql.org/docs/current/static/libpq-pgpass.html |
55 .. _`here` : http://www.postgresql.org/docs/current/static/libpq-pgpass.html |
57 .. _`backup-ninja` : https://labs.riseup.net/code/projects/show/backupninja/ |
56 .. _`backup-ninja` : https://labs.riseup.net/code/projects/show/backupninja/ |
58 .. _`backuppc` : http://backuppc.sourceforge.net/ |
57 .. _`backuppc` : http://backuppc.sourceforge.net/ |
|
58 |
|
59 .. warning:: |
|
60 |
|
61 Remember that these indications will fail you whenever you use |
|
62 another database backend than postgres. Also it does properly handle |
|
63 externally managed data such as files (using the Bytes File System |
|
64 Storage). |