-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_Database_Maintenance.sh
49 lines (40 loc) · 1.27 KB
/
04_Database_Maintenance.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
#!/bin/bash
# Import settings
scripts_dir=$(dirname "$0")
source $scripts_dir/settings_backup.ini
maintenance_type=$1
#########################
### MAINTENANCE TASKS ###
#########################
if [ $maintenance_type = "Full" ];
then
##
## Full maintenance
## By default, Full maintenance is launched at the same time as full backups
## Vacuum full on all database tables + Reindex
##
echo "Launching full maintenance"
echo "=========================="
echo "Enabling maintenance mode for GeoNature..."
cd /etc/apache2/sites-available
sudo a2ensite geonature_maintenance.conf
sudo a2dissite geonature.conf
sudo apachectl restart
echo "Vacuum : cleaning all tables..."
sudo psql -h localhost -U $pg_superuser -d $db_name -c "VACUUM FULL;"
echo "Reindex database..."
sudo psql -h localhost -U $pg_superuser -d $db_name -c "REINDEX DATABASE flaviabase;"
echo "Reactivating GeoNature..."
sudo a2dissite geonature_maintenance.conf
sudo a2ensite geonature.conf
sudo apachectl restart
cd /home/$linux_user
else
##
## Daily maintenance
## Only vaccum analyze on all database
##
echo "Launching daily database maintenance..."
echo "Vacuum : cleaning all tables..."
sudo psql -h localhost -U $pg_superuser -d $db_name -c "VACUUM ANALYZE;"
fi