Skip to content

Instantly share code, notes, and snippets.

@thisni1s
Last active March 27, 2021 21:14
Show Gist options
  • Save thisni1s/23276990d048ea9facbe05e6e688e595 to your computer and use it in GitHub Desktop.
Save thisni1s/23276990d048ea9facbe05e6e688e595 to your computer and use it in GitHub Desktop.
Mailcow backup script w/ PGP and SCP
#!/bin/bash
NOW=$(date '+%d-%m-%y')
BDIR=/opt/mailcow-dockerized/backups/backup-${NOW}
mkdir $BDIR
MAILCOW_BACKUP_LOCATION=$BDIR /opt/mailcow-dockerized/helper-scripts/backup_and_restore.sh backup all
cp /opt/mailcow-dockerized/mailcow.conf $BDIR/.
tar -czvf /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz $BDIR
gpg --encrypt --sign -r [email protected] -o /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz.gpg --passphrase-file /path/to/file --batch --pinentry-mode loopback /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz
scp -P 1337 /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz.gpg user@host:/home/user/backups/.
rm /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz.gpg
rm /opt/mailcow-dockerized/backups/backup-${NOW}.tar.gz
rm -rf $BDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment