From 428fe8ce78c4bd6307b7d3a0250fe672eb080188 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Mon, 15 Jul 2019 13:30:28 -0300 Subject: [PATCH] Organizing Backup scripts --- .gitignore | 4 ++++ Services/.localBackupPath_TEMPLATE | 1 + Services/.serverBackupPath_TEMPLATE | 1 + Services/.sshKey_TEMPLATE | 1 + Services/backup-db.sh | 9 +++++++++ Services/backup-files.sh | 9 +++++++++ 6 files changed, 25 insertions(+) create mode 100644 .gitignore create mode 100644 Services/.localBackupPath_TEMPLATE create mode 100644 Services/.serverBackupPath_TEMPLATE create mode 100644 Services/.sshKey_TEMPLATE create mode 100755 Services/backup-db.sh create mode 100755 Services/backup-files.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c50eed --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.localBackupPath +.serverBackupPath +.sshKeyBackupPath +.sshKey diff --git a/Services/.localBackupPath_TEMPLATE b/Services/.localBackupPath_TEMPLATE new file mode 100644 index 0000000..1c7c918 --- /dev/null +++ b/Services/.localBackupPath_TEMPLATE @@ -0,0 +1 @@ +/my/local/backup diff --git a/Services/.serverBackupPath_TEMPLATE b/Services/.serverBackupPath_TEMPLATE new file mode 100644 index 0000000..deca4eb --- /dev/null +++ b/Services/.serverBackupPath_TEMPLATE @@ -0,0 +1 @@ +sshBackupUser@serverIp:/my/backup/path diff --git a/Services/.sshKey_TEMPLATE b/Services/.sshKey_TEMPLATE new file mode 100644 index 0000000..156085f --- /dev/null +++ b/Services/.sshKey_TEMPLATE @@ -0,0 +1 @@ +/home/myUser/.ssh/id_rsa_backup diff --git a/Services/backup-db.sh b/Services/backup-db.sh new file mode 100755 index 0000000..0f71c5a --- /dev/null +++ b/Services/backup-db.sh @@ -0,0 +1,9 @@ +#! /bin/bash +sshKey=$(<.sshKey) +serverBackupPath=$(<.serverBackupPath) +localPath=$(<.localBackupPath) + +/bin/rsync -r -e "ssh -i $sshKey" "$serverBackupPath/db/*" "$localPath/db/" + +# Delete files older than 15 days +find "$localPath/db" -type f -name "*.sql.gz" -mtime +15 -delete diff --git a/Services/backup-files.sh b/Services/backup-files.sh new file mode 100755 index 0000000..6927cb6 --- /dev/null +++ b/Services/backup-files.sh @@ -0,0 +1,9 @@ +#! /bin/bash +sshKey=$(<.sshKey) +serverBackupPath=$(<.serverBackupPath) +localPath=$(<.localBackupPath) + +/bin/rsync -r -e "ssh -i $sshKey" "$serverBackupPath/files/*" "$localPath/files/" + +# Delete files older than 30 days +find "$localPath/files" -type f -name "*.*" -mtime +30 -delete