-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbackup-zabbix7.sh
54 lines (42 loc) · 1.69 KB
/
backup-zabbix7.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
#!/bin/bash
#backup frontend,alert scripts, external scripts e databases mysql zabbix
# para importar o dump do banco de dado, executar este comando mysqldump -u username -p database_name > data-dump.sql
#set variaveis
user="zabbix"
password="password"
host="localhost"
db_name="zabbix"
# Other options backup_path="/home/backup"
backup_path="/opt/backup"
date=$(date +"%d-%b-%Y")
# Aplicar permissões
umask 177
# Create directory backup
mkdir $backup_path
mkdir $backup_path/backup-$date
mkdir $backup_path/backup-$date/frontend
mkdir $backup_path/backup-$date/alertscripts
mkdir $backup_path/backup-$date/externalscripts
mkdir $backup_path/backup-$date/database
mkdir $backup_path/backup-$date/fileconf
mkdir $backup_path/backup-$date/fileconf/mysql
# Dump database into SQL file
mysqldump --user=$user --password=$password --host=$host $db_name --single-transaction --skip-lock-tables > $backup_path/backup-$date/database/$db_name-$date.sql.bkp
# Delete files older than 30 days
find $backup_path/backup-$date/database/* -mtime +30 -exec rm {} \;
# Backup Frontend
cp -R /usr/share/zabbix/* $backup_path/backup-$date/frontend
# Alert Scripts
cp -R /usr/lib/zabbix/alertscripts/* $backup_path/backup-$date/alertscripts
# External Scripts
cp -R /usr/lib/zabbix/externalscripts/* $backup_path/backup-$date/externalscripts
# Files Cofiguration
cp -R /etc/zabbix/* $backup_path/backup-$date/fileconf
# File Cofiguration my.cnf
cp -R /etc/mysql/mariadb.conf.d/50-server.cnf $backup_path/backup-$date/fileconf/mysql
# File Cofiguration my.cnf
cp -R /etc/mysql/* $backup_path/backup-$date/fileconf/mysql
# Add File to .tar
tar -cvf $backup_path/backup-$date.tar
# Add File to .tar.gz
gzip $backup_path/backup-$date.tar