Fr:Backups

From Davical
Revision as of 18:40, 22 February 2011 by Tikismoke (talk)
Jump to navigationJump to search
Help
Available languages
Besoin de traduction Cet article ou cette section nécessitent d'être traduits depuis l'article Backups.

Si vous connaissez bien l'anglais, n'hésitez pas ! Merci pour 'DAViCal'.

Sauvzgarde complete

Full backup

  • Les donnees de DAViCal sont enregistrees dans une base de donees PostgreSQL. Vous devriez les sauvegarder periodiquement avec la commande PostgreSQL pg_dump:
  • The DAViCal data is stored in the PostgreSQL database. You should back this up periodically using the PostgreSQL pg_dump command:
pg_dump -Fc davical >davical.pgdump
  • Pour restaurer la base de donnees utilisez la commande PostgreSQL pg_restore:
  • To restore the database use the PostgreSQL command pg_restore:
createdb --owner davical_dba --encoding UTF8 --template template0 davical
pg_restore -Fc -d davical davical.pgdump

Note

Si vous restaurer sur un nouveau serveur vous devrez creez la table des utilisateurs (habituellement 'davical_dba' et 'davical_app'), et vous devrez probablement alter le fichier pg_hba.cong comme lors d'une nouvelle installation. If you are restoring on a new server you will need to create the database users (usually 'davical_dba' and 'davical_app'), and you will probably also need to alter the pg_hba.conf as for a new installation.

Sauvegarde incrementale

Incremental backup

PostgreSQL supporte les sauvegardes incrementale automatique.

"Qu'est ce que cela signifie?"
PostgreSQL supports automatic incremental backups.

What does this mean?
Au lieu de sauvegarder la base de donnee entiere -et devoir se souvenir de ke faire- PostgreSQL enregistrera les modifications dans des 'fichiers incrementes'. Instead of backing up the entire database - and having to remember to do it - PostgreSQL will store the changes in 'increment files'.

Why should you care?
vous devriez toujours garder de multiple sauvegarde de n'importe quel base de donnees. Si par exemple, vous ne conservez qu'une seule sauvegarde et qu'accidentellement vous effacer un evenement et ecrasez votre sauvegarde, vous ne pourrez jamais restaurer ce dernier. You should always keep multiple backups of any database you have. If, for example, you only have one backup and you accidentally delete an event and overwrite your previous backup, you cannot recover that event.

L'inconvenient de conserver plusieurs sauvegarde et l'utilisation rapide d'espace disque. Donc au lieux d'avoir plusieurs sauvegardes complete, il est plus judicieux de conserver une sauvegardr complete et d'enregistrer ke s changements au fur et a mesure depuis cette derniere. The trouble with keeping multiple backups is that you use a lot of disk space very quickly. So instead of having multiple complete backups, it makes sense to have a complete backup and store incremental changes from that complete backup.

Benfuces des sauvegatdes incrementales:

  • restauration a un moment precis
  • sauvegardes autolatiques
  • taille des sauvegardes optimisee

Having incremental backups has the following benefits:

  • Point-in-time restorations
  • Automatic backups
  • Space efficient backups

Il est important de noter que kes sauvegardes incrementale d'effectue sur k'ensemble des bases de donnees et pas seulement les tables de DAViCal. It is important to note that incremental backups backup the entire database cluster, not just the DAViCal database.

How to set up incremental backups

The PostgreSQL manual has a page on continuous archiving, which gives you a complete guide on how to do incremental backups and should be read to understand what is going on.

Here is a basic guide to setting up incremental backups:

Create a backup directory and set permissions

mkdir /var/backups/postgres/
chown postgres:postgres /var/backups/postgres/
chmod 750 /var/backups/postgres/

Create a backup script
Here is an example I store in /usr/local/bin/postgres-backup.

#!/bin/bash

BACKUP_DIR="/var/backups/postgres"
POSTGRES_MANUAL="http://www.postgresql.org/docs/8.3/static/continuous-archiving.html"
NOTIFY_EMAIL="root"
NOTIFY_SUBJECT="Postgres backup fail - $0"

# Check if the correct number of arguments have been given
if test ${BASH_ARGC} -ne 2;
then
    echo "The incorrect number of arguments were supplied"
    exit 1;
fi

# Copy arguments into friendlier variable names
SRC_FILE=${1}
DST_FILENAME=${2}

# Test if backup directory exists
if test ! -d ${BACKUP_DIR};
then
    echo "The usual postgres incremental backup has failed, the ${BACKUP_DIR} directory does not exist. Look at ${POSTGRES_MANUAL}" | mail -s "${NOTIFY_SUBJECT}" ${NOTIFY_EMAIL};
    exit 1;
fi;

# Test if the source file exists
if test ! -f ${SRC_FILE};
then
    echo "The usual postgres incremental backup has failed, the source file (${SRC_FILE}) does not exist. Look at ${POSTGRES_MANUAL}" | mail -s "${NOTIFY_SUBJECT}" ${NOTIFY_EMAIL};
    exit 1;
fi;

# Test if backup increment already exists
if test ! -f ${BACKUP_DIR}/${DST_FILENAME}.gz;
then
    # Make a compressed copy of the increment to the backup directory
    gzip -c ${SRC_FILE} > ${BACKUP_DIR}/${DST_FILENAME}.gz &&
    # If you have included the postgres user in the backup group, uncomment the line below
    # Make the copy readable by the backup group
#   chgrp backup /var/backups/postgres/${DST_FILENAME}.gz &&
    # Make the copy readable by the owner and group only
    chmod 440 ${BACKUP_DIR}/${DST_FILENAME}.gz;
else
    echo "The usual postgres incremental backup has failed, there is a filename conflict (${DST_FILENAME}). Look at ${POSTGRES_MANUAL}" | mail -s "${NOTIFY_SUBJECT}" ${NOTIFY_EMAIL};
    exit 1;
fi

Make the script executable

chown postgres:postgres /usr/local/bin/postgres-backup
chmod 550 /usr/local/bin/postgres-backup

Modify PostgreSQL to do archiving
You need to modify your postgresql.conf, which, on Debian, is stored in /etc/postgresql/8.3/main/
These options need to be changed.

archive_mode = on                                        # Turn on archiving
archive_command = '/usr/local/bin/postgres-backup %p %f' # What command to run
archive_timeout = 86400                                  # Do a forced backup every 7 days

Reload PostgreSQL

/etc/init.d/postgresql-8.3 reload

Start a full database cluster backup

sudo -u postgres psql
postgres=# SELECT pg_start_backup('/var/backups/postgres/');
postgres=# \q

Backup the full database cluster

tar czvf /var/backups/postgres/fullbackup-$(date +%Y%m%d).tar.gz /var/lib/postgresql/8.3/main/base/

Stop the full database cluster backup

sudo -u postgres psql
postgres=# SELECT pg_stop_backup();
postgres=# \q

You are done!

How to restore incremental backups

The PostgreSQL manual has a page on continuous archiving, which also guides you on how to do recover a database using incremental backups.

Besoin de relécture Cet article ou cette section nécessitent d'être 'relu'. Si vous connaissez bien le français, n'hésitez pas! Merci pour DAViCal.