doc/book/admin/additional-tips.rst
changeset 10491 c67bcee93248
parent 5400 b7ab099b128a
equal deleted inserted replaced
10490:76ab3c71aff2 10491:c67bcee93248
       
     1 
       
     2 .. _Additional Tips:
       
     3 
       
     4 Backups (mostly with postgresql)
       
     5 --------------------------------
       
     6 
       
     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.
       
    11 
       
    12 Using postgresql (and only that)
       
    13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    14 
       
    15 Before you
       
    16 go ahead, make sure the following permissions are correct ::
       
    17 
       
    18    # chgrp postgres /var/lib/cubicweb/backup
       
    19    # chmod g+ws /var/lib/cubicweb/backup
       
    20    # chgrp postgres /etc/cubicweb.d/*<instance>*/sources
       
    21    # chmod g+r /etc/cubicweb.d/*<instance>*/sources
       
    22 
       
    23 Simply use the pg_dump in a cron installed for `postgres` user on the database server::
       
    24 
       
    25     # m h  dom mon dow   command
       
    26     0 2 * * * pg_dump -Fc --username=cubicweb --no-owner <instance> > /var/backups/<instance>-$(date '+%Y-%m-%d_%H:%M:%S').dump
       
    27 
       
    28 Using :command:`cubicweb-ctl db-dump`
       
    29 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
    30 
       
    31 The CubicWeb way is to use the :command:`db-dump` command. For that,
       
    32 you have to put your passwords in a user-only-readable file at the
       
    33 home directory of root user.  The file is `.pgpass` (`chmod 0600`), in
       
    34 this case for a socket run connection to PostgreSQL ::
       
    35 
       
    36     /var/run/postgresql:5432:<instance>:<database user>:<database password>
       
    37 
       
    38 The postgres documentation for the `.pgpass` format can be found `here`_
       
    39 
       
    40 Then add the following command to the crontab of the user (`crontab -e`)::
       
    41 
       
    42     # m h  dom mon dow   command
       
    43     0 2 * * * cubicweb-ctl db-dump <instance>
       
    44 
       
    45 
       
    46 Backup ninja
       
    47 ~~~~~~~~~~~~
       
    48 
       
    49 You can use a combination `backup-ninja`_ (which has a postgres script in the
       
    50 example directory), `backuppc`)_ (for versionning).
       
    51 
       
    52 Please note that in the *CubicWeb way* it adds a second location for your
       
    53 password which is error-prone.
       
    54 
       
    55 .. _`here` : http://www.postgresql.org/docs/current/static/libpq-pgpass.html
       
    56 .. _`backup-ninja` : https://labs.riseup.net/code/projects/show/backupninja/
       
    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).