#!/bin/sh
NOW=$(date +"%Y-%m-%d")
DELETE_IN=$(date +"%Y-%m-%d" -d "-3 days")
# Backup Principal
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_principal | gzip > /home/agenci30/erpempresa.com/backups_database/principal/backup-$NOW.sql.gz
# Backup Controle
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_controle | gzip > /home/agenci30/erpempresa.com/backups_database/controle/backup-$NOW.sql.gz
# Backup Sistema
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_sistema | gzip > /home/agenci30/erpempresa.com/backups_database/sistema/backup-$NOW.sql.gz
# Backup Financeiro
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_financeiro | gzip > /home/agenci30/erpempresa.com/backups_database/financeiro/backup-$NOW.sql.gz
# Backup Painel
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_painel | gzip > /home/agenci30/erpempresa.com/backups_database/painel/backup-$NOW.sql.gz
# Backup Gestor
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_gestor | gzip > /home/agenci30/erpempresa.com/backups_database/gestor/backup-$NOW.sql.gz
# Backup Contas
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_contas | gzip > /home/agenci30/erpempresa.com/backups_database/contas/backup-$NOW.sql.gz
# Backup Contas
/usr/bin/mysqldump --user='agenci30_erp' --password='%&B5A*MkTWl&' --host='localhost' agenci30_erp_central | gzip > /home/agenci30/erpempresa.com/backups_database/central/backup-$NOW.sql.gz
# Delete old backups
rm -rf /home/agenci30/erpempresa.com/backups_database/principal/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/controle/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/sistema/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/financeiro/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/painel/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/gestor/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/contas/backup-$DELETE_IN.sql.gz

rm -rf /home/agenci30/erpempresa.com/backups_database/central/backup-$DELETE_IN.sql.gz