-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackup_script_lab.txt
49 lines (36 loc) · 1.48 KB
/
backup_script_lab.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Étape 1 : Créer un script shell de backup mysql_backup:
#!/bin/sh
#----------------------------------------------------
# a simple mysql database backup script for traininees.
# version 1, updated November 27, 2019.
#----------------------------------------------------
# This work is licensed under a Creative Commons
# Attribution-ShareAlike 3.0 Unported License;
# see http://creativecommons.org/licenses/by-sa/3.0/
# for more information.
#----------------------------------------------------
# (1) set up all the mysqldump variables
FILE=minime.sql.`date +"%Y%m%d"`
DBSERVER=127.0.0.1
DATABASE=dbname
USER=username
PASS=password
# (2) in case you run this more than once a day, remove the previous version of the file
unalias rm 2> /dev/null
rm ${FILE} 2> /dev/null
rm ${FILE}.gz 2> /dev/null
# (3) do the mysql database backup (dump)
# use this command for a database server on a separate host:
#mysqldump --opt --protocol=TCP --user=${USER} --password=${PASS} --host=${DBSERVER} ${DATABASE} > ${FILE}
# use this command for a database server on localhost. add other options if need be.
mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} > ${FILE}
# (4) gzip the mysql database dump file
gzip $FILE
# (5) show the user the result
echo "${FILE}.gz was created:"
ls -l ${FILE}.gz
Rajouter les permissions nécessaires à l'execution de ce fichier.
Étape 2: créer un cron pour lancer backup toutes les 10 minutes:
>crontab -e
add this line:
*/10 * * * * /mysql_backup.sh