Copie de sécurité » Historique » Version 2
Patrice Nadeau, 2015-05-07 12:27
1 | 1 | Patrice Nadeau | h1. Copie de sécurité |
---|---|---|---|
2 | |||
3 | 2 | Patrice Nadeau | Remplacer les items suivants : |
4 | * *username* : Usager de la base de donnés. |
||
5 | * *password* : Mot de passe de la base de donnés. |
||
6 | * *database* : Nom de la base de données. |
||
7 | * *path* : Emplacement pour recevoir le fichier. |
||
8 | |||
9 | <pre><code class="bash"> |
||
10 | /usr/bin/mysqldump -u username -p password database | gzip > /path/redmine_`date +%y_%m_%d`.gz |
||
11 | rsync -a /srv/redmine/files /path/ |
||
12 | </code></pre> |
||
13 | |||
14 | Script un peu plus évolué : |
||
15 | <pre> <code class="bash"> |
||
16 | |||
17 | #!/bin/bash |
||
18 | # |
||
19 | # backup_redmine.sh |
||
20 | # Backup of a Redmine setup |
||
21 | # Last Changes: 2013-02-23 |
||
22 | # Maintainer: Patrice Nadeau <pnadeau@patricenadeau.com> |
||
23 | |||
24 | # TODO Verify the results (folder exist, enough disk pace , etc..) |
||
25 | |||
26 | ## The only variable needed to be changed |
||
27 | # Directory of the Redmine install |
||
28 | declare -r RAIL_ROOT='/srv/redmine' |
||
29 | # MySQL database |
||
30 | declare -r MYSQL_DB='' |
||
31 | # MySQL username for the Redemine db |
||
32 | declare -r MYSQL_USER='' |
||
33 | # MySQL password for the Redemine db |
||
34 | declare -r MYSQL_PASSWORD='' |
||
35 | # Directory for the backup (must exist and with no space in the name) |
||
36 | declare -r DIR='/root' |
||
37 | ## end |
||
38 | |||
39 | # Exit level |
||
40 | declare -ir EXIT_OK=0 |
||
41 | declare -ir EXIT_WARNING=1 |
||
42 | declare -ir EXIT_ERROR=2 |
||
43 | |||
44 | declare -i STATUS=$EXIT_OK |
||
45 | |||
46 | # The directory inside the archive |
||
47 | declare -r REDMINE='redmine' |
||
48 | TMP_DIR=$DIR/$REDMINE |
||
49 | |||
50 | # This will be used for the archive file |
||
51 | declare -r DST=$DIR/redmine_$(date +%Y%m%d_%H%M%S).tar.gz |
||
52 | |||
53 | # The temporary sql file |
||
54 | declare -r TMP_MYSQL=$TMP_DIR/$MYSQL_DB.mysql |
||
55 | |||
56 | echo "Backup in progress in $DST" |
||
57 | |||
58 | #### Create the temp directory #### |
||
59 | mkdir $TMP_DIR |
||
60 | |||
61 | #### backup MySQL #### |
||
62 | if [ $STATUS -eq $EXIT_OK ] |
||
63 | then |
||
64 | STEP='Creating MySQL backup' |
||
65 | mysqldump --user=$MYSQL_USER --password=$MYSQL_PASSWORD $MYSQL_DB \ |
||
66 | > $TMP_MYSQL |
||
67 | STATUS=$? |
||
68 | fi |
||
69 | |||
70 | #### backup the Redmine folder #### |
||
71 | if [ $STATUS -eq $EXIT_OK ] |
||
72 | then |
||
73 | STEP='Creating Redmine'"'"' files backup' |
||
74 | cp --recursive $RAIL_ROOT $TMP_DIR |
||
75 | STATUS=$? |
||
76 | fi |
||
77 | |||
78 | #### create the archive file #### |
||
79 | if [ $STATUS -eq $EXIT_OK ] |
||
80 | then |
||
81 | STEP="Creating archive" |
||
82 | tar --create --gzip --file $DST --directory=$DIR $REDMINE |
||
83 | STATUS=$? |
||
84 | fi |
||
85 | |||
86 | #### cleanup #### |
||
87 | if [ $STATUS -eq $EXIT_OK ] |
||
88 | then |
||
89 | STEP='Cleaning up' |
||
90 | rm --recursive --force $TMP_DIR |
||
91 | STATUS=$? |
||
92 | fi |
||
93 | |||
94 | #### exit #### |
||
95 | if [ $STATUS -eq $EXIT_OK ] |
||
96 | then |
||
97 | echo "Backup done" |
||
98 | else |
||
99 | echo "Bakup failed with error code $STATUS in step $STEP" |
||
100 | fi |
||
101 | |||
102 | |||
103 | exit $STATUS |
||
104 | |||
105 | </code></pre> |
||
106 | |||
107 | 1 | Patrice Nadeau | |
108 | h2. Script Bash pour faire une copie de sécurité des données du logiciel Redmine |
||
109 | |||
110 | |||
111 | h2. Utilisation |
||
112 | |||
113 | Simplement changer les 4 variables situées au début du script |
||
114 | * 3 pour MySQL |
||
115 | * 1 pour la destination de la copie |
||
116 | |||
117 | Rendre le script exécutable |
||
118 | * *chmod +x backup_redmine.sh* |
||
119 | |||
120 | Et exécuter |
||
121 | * *./backup_redmine.sh* |
||
122 | |||
123 | h2. Téléchargement |
||
124 | |||
125 | * "Script":/attachments/download/45 |