source: cpc/trunk/project/bin/autodump @ 1316

Last change on this file since 1316 was 1012, checked in by teymour, 11 years ago

Encore un peu plus générique

  • Property svn:executable set to *
File size: 1.2 KB
Line 
1#!/bin/bash
2if [ -z "$1" ] ; then
3source bin/db.inc
4else
5source $1
6fi
7
8mysqldump $MYSQLID $DBNAME -q --single-transaction --add-drop-table -R -t --disable-keys --complete-insert | gzip > $DUMPDIR/$DBNAME.$(date +%y%m%d).sql.gz
9
10# On archive tous les 1er du mois et tous les dimanches
11if [[ $(date +%-w) -eq 0 || $(date +%-d) -eq 1 ]]; then
12  cp $DUMPDIR/$DBNAME.$(date +%y%m%d).sql.gz $DUMPDIR/archives/
13fi
14
15# On efface tous les mois les archives hebdomadaires vieilles de plus d'un mois mais on garde l'archive mensuelle
16if [[ $(date +%-d) -eq 1 ]]; then
17  if [[ $(date +%-m) -le 2 ]]; then
18    year0=`expr $(date +%y) - 1`
19    month0=`expr $(date +%m) + 10`
20  else
21    year0=`expr $(date +%y) + 0`
22    month0=`expr $(date +%m) - 2`
23  fi
24  ym=`printf "%02d%02d" $year0 $month0`
25  rm -f `ls $DUMPDIR/archives/$DBNAME.${ym}*.sql.gz | grep -v $DBNAME.${ym}01.sql.gz`
26fi
27
28# On efface les dumps vieux de plus d'une semaine
29if [[ $(date +%-d) -le 7 ]]; then
30  day0=`expr $(date +%d) + 21`
31else
32  day0=`expr $(date +%d) - 7`
33fi
34rm -f $DUMPDIR/$DBNAME.*`printf "%02d" $day0`.sql.gz
35if [[ $(date +%-d) -eq 8 ]]; then
36  rm -f $DUMPDIR/$DBNAME.*29.sql.gz
37  rm -f $DUMPDIR/$DBNAME.*30.sql.gz
38  rm -f $DUMPDIR/$DBNAME.*31.sql.gz
39fi
40
Note: See TracBrowser for help on using the repository browser.