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