forked from fzampirolli/mctest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_myBackup.sh
81 lines (61 loc) · 2.47 KB
/
_myBackup.sh
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
cd /home/fz/django_webmctest/
#cp __settings.env ../
source _settings.env
source AmbientePython3/bin/activate
cd mctest
killall - kill python3
source ../runDjango.sh &
#################### SCRIPT PARA BACKUP MYSQL ####################
# mysqldump --no-defaults -u root -p DB_MCTest > mctest.sql
DB_PARAM='--no-defaults -h $IP_HOST'
echo " -- Definindo parametros do sistema ..."
DATE=$(date +%Y-%m-%d)
MYSQLDUMP=/usr/bin/mysqldump
BACKUP_DIR=/backup/mysql
BACKUP_NAME=mysql-$DATE.sql
BACKUP_TAR=mysql-$DATE.tar
PATH_MCTest=/home/fz/django_webmctest
PYTHON=/home/fz/django_webmctest/AmbientePython3/bin/python3
echo " -- in $IP_HOST"
echo " -- Gerando Backup da base de dados $DB_NAME em $BACKUP_DIR/$BACKUP_NAME ..."
$MYSQLDUMP $DB_PARAM -u $DB_USER -p$DB_PASS $DB_NAME -h $IP_HOST> $BACKUP_DIR/$BACKUP_NAME
# mysqldump --no-defaults -u root -p DB_MCTest -h 177.104.60.18 > mysql-2019-09--2.sql
# Compactando arquivo em tar
echo " -- Compactando arquivo em tar ..."
tar -cjf $BACKUP_DIR/$BACKUP_TAR -C $BACKUP_DIR $BACKUP_NAME --remove-files
# descompactar um tar
# tar xvjf file.tar
# Excluindo arquivos desnecessarios
echo " -- Excluindo arquivos desnecessarios ..."
rm -rf $BACKUP_DIR/$BACKUP_NAME
# Excluindo arquivos antigos > 90 dias
find /backup/*/* -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/tmp*/* -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/tmp/imgs180days/* -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/pdf*/* -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/*.pdf -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/*.tex -type f -mtime +90 | xargs rm
find $PATH_MCTest/mctest/*.csv -type f -mtime +90 | xargs rm
# renomeando log grande
find $PATH_MCTest/mctest/ -iname "*.log" -size +1M -exec mv {} "correct-$DATA.log.backup" \;
#################### SCRIPT PARA BACKUP JSON ####################
# python3 manage.py dumpdata --indent 2 > db.json
echo " -- backup json ..."
cd $PATH_MCTest
source AmbientePython3/bin/activate
cd mctest
$PYTHON manage.py shell < _clearsessions.py
BACKUP_DIR=/backup/json
BACKUP_NAME=json-$DATE.json
BACKUP_TAR=json-$DATE.tar
DB_PARAM='manage.py dumpdata --indent 2'
$PYTHON $DB_PARAM >$BACKUP_DIR/$BACKUP_NAME
tar -cjf $BACKUP_DIR/$BACKUP_TAR -C $BACKUP_DIR $BACKUP_NAME --remove-files
rm -rf $BACKUP_DIR/$BACKUP_NAME
echo " -- backup tmpGAB ..."
BACKUP_DIR=/backup/tmpGAB
BACKUP_NAME=tmpGAB
BACKUP_TAR=tmpGAB-$DATE.tar
tar -cjf $BACKUP_DIR/$BACKUP_TAR $BACKUP_NAME
#rm -rf $BACKUP_DIR/$BACKUP_NAME