From 5d263730e4f7c9e98afdc3c56aedc8e4e8425871 Mon Sep 17 00:00:00 2001 From: zwnk Date: Mon, 8 May 2023 17:05:11 -0400 Subject: [PATCH] first --- btrbk.conf | 23 +++++++++++++++++++++++ btrfs_bckp.sh | 19 +++++++++++++++++++ btrfs_scrub.sh | 12 ++++++++++++ sendEmail.ps1 | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 btrbk.conf create mode 100644 btrfs_bckp.sh create mode 100644 btrfs_scrub.sh create mode 100644 sendEmail.ps1 diff --git a/btrbk.conf b/btrbk.conf new file mode 100644 index 0000000..3b20a88 --- /dev/null +++ b/btrbk.conf @@ -0,0 +1,23 @@ +snapshot_preserve_min 7d +snapshot_preserve 14d + +target_preserve_min latest +target_preserve 3d 1w 1m + +snapshot_dir btrbk_snapshots + +incremental yes + +# first btrfs volume +volume /mnt/cloud + target /mnt/backup + subvolume seafile + subvolume geoserver + subvolume onlynext + subvolume rocket_chat + +# second btrfs volume +volume /mnt/data + target /mnt/backup + subvolume db_rocket.chat + subvolume nextcloud_db diff --git a/btrfs_bckp.sh b/btrfs_bckp.sh new file mode 100644 index 0000000..ce94cda --- /dev/null +++ b/btrfs_bckp.sh @@ -0,0 +1,19 @@ + +# EXAMPLE CRONJOB: +# 0 2 * * * /mnt/cloud/nc_dmcl/btrbk/btrfs_bckp.sh > /var/log/backup/btrfs_log.log + +# stop services and snapshot + +#Backup +# brtbk was present as a local copy in /mnt/cloud/nc_dmcl/btrbk ... +cd /mnt/cloud/nc_dmcl/btrbk/ +./btrbk -c /mnt/cloud/nc_dmcl/btrbk/btrbk.conf run +btrfs device stats /mnt/cloud/ +btrfs device stats /mnt/backup/ +btrfs device stats /mnt/db_ssd/ + +# send mail with logfile +docker run --rm -v /var/log/backup/:/attachment mcr.microsoft.com/powershell pwsh /external/sendEmail.ps1 + +# start services + diff --git a/btrfs_scrub.sh b/btrfs_scrub.sh new file mode 100644 index 0000000..d8275b5 --- /dev/null +++ b/btrfs_scrub.sh @@ -0,0 +1,12 @@ +# 0 0 * * SAT /mnt/cloud/nc_dmcl/btrbk/btrfs_scrub.sh > /var/log/backup/btrfs_log.log + +for fs in $(grep ' btrfs ' /proc/mounts | cut -d' ' -f1 | sort -u) +do + starttime="$(date "+%Y-%m-%d %H:%M:%S")" + printf "Starting btrfs scrub on $fs" + btrfs scrub start -Bd "$fs" + journalctl -q -k --since "$starttime" | grep BTRFS + printf "Scrub for $fs has finished" +done + +docker run --rm -v /mnt/cloud/nc_dmcl/btrbk/scrub/:/attachment mcr.microsoft.com/powershell pwsh /external/sendEmail.ps1 diff --git a/sendEmail.ps1 b/sendEmail.ps1 new file mode 100644 index 0000000..a3a68fc --- /dev/null +++ b/sendEmail.ps1 @@ -0,0 +1,41 @@ +<# + Simple script to send a log file after btrfs backup +#> + +$EmailAttachments = "/attachment/btrfs_log.log" + +# Email Setup +$SMTPServer = "mx.digimapas.cl" +$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) +$SMTPClient.EnableSsl = $true +$user = "no_reply_it@digimapas.cl" +$pw = ConvertTo-SecureString "PASSWORD" -AsPlainText -Force +$SMTPClient.Credentials = New-Object System.Management.Automation.PSCredential($user, $pw) +$emailMessage = New-Object System.Net.Mail.MailMessage +$emailMessage.From = new-object System.Net.Mail.MailAddress($user, "Backup ...") +$emailMessage.to.Add("RECEIVER@digimapas.cl") +$emailMessage.From = $user +$emailMessage.IsBodyHTML = $false + + +<# + to create readablity the email is formatted as html table +#> +$htmlEmailBody = ("Backup ...`n") + +foreach($line in Get-Content $EmailAttachments) { + $htmlEmailBody += @($line) + $htmlEmailBody += @("`n") +} + + +if($EmailAttachments.length -gt 0){ + foreach($EmailAttachment in $EmailAttachments){ + Write-Host $EmailAttachment + $emailMessage.Attachments.Add($EmailAttachment) + } +} +$emailMessage.Subject = "Backup Webservices DMCL" +$emailMessage.Body = "$htmlEmailBody" +$SMTPClient.Send($emailMessage) +