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