source: cpc/trunk/project/bin/autodump_test @ 1000

Last change on this file since 1000 was 1000, checked in by roux, 11 years ago

dumps automatiques quotidiens de la base avec archivage sélectif reste à faire un miroir

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