Last active
November 5, 2018 09:20
-
-
Save abyssluke/fc7aad328bbf8714bb486cc2fdfbbcf8 to your computer and use it in GitHub Desktop.
Mail Backup Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#生成されるファイルのパーミッションをrw-------(600)にする | |
umask 077 | |
####設定ここから#### | |
#メールスプールフォルダのある場所(スプールフォルダを指定するのではない) | |
curdir="$HOME" | |
#メールスプールのフォルダ名 | |
mailspool="Mail" | |
#バックアップ先のパス | |
dirpath='/path/to/MailBackup' | |
#パスワード文字列が入ったファイル(パーミッションを600以下に設定すること!!) | |
passwdfile='/path/to/.MailBackupPasswd' | |
#アップロード先のS3バケット | |
uploadbucket='thisisexamplebucket' | |
#アップロード先のS3のプリフィックス | |
#(ディレクトリ。/(ルート)にアップロードする場合は未指定とし、指定する場合は/から始めること。末尾に/は不要) | |
#例: /mailbackup | |
uploadprefix='' | |
#S3のアップロードオプション(aws s3で指定できるオプション) | |
#エラー時のみログを記録させたいので--only-show-errorsを指定している。 | |
uploadoptions='--sse --only-show-errors' | |
#ファイル名のプリフィックス(固定部分) | |
nameprefix='SylpheedBackup' | |
#ファイル名(可変部分。日付) | |
filename=`date +%y%m%d%H%M%S` | |
####設定ここまで#### | |
#圧縮 | |
tar czf $dirpath/$nameprefix$filename.tar.gz -C $curdir $mailspool | |
#暗号化 | |
gpg --batch --passphrase-fd 0 --symmetric $dirpath/$nameprefix$filename.tar.gz < $passwdfile | |
#暗号化前のファイルを抹消 | |
#SSDにバックアップする場合shredの使用はおすすめできないかも。 | |
shred -u $dirpath/$nameprefix$filename.tar.gz | |
#S3へアップロード(要awscli) | |
aws s3 cp $uploadoptions $dirpath/$nameprefix$filename.tar.gz.gpg s3://$uploadbucket$uploadprefix/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Sylpheed Mail Spool Backup | |
[Service] | |
Type=oneshot | |
ExecStart=/path/to/mailbackup.sh | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Sylpheed Mail Spool Backup | |
[Timer] | |
OnCalendar=Sun *-*-* 05:00:00 | |
Persistent=true | |
RandomizedDelaySec=15s | |
Unit=SylpheedMailBackup.service | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment