Add aws s3 versioning and lifecycles to backup.
authorLuke Hoersten <luke@hoersten.org>
Sat, 03 Jul 2021 13:24:52 -0500
changeset 157 5e5c9e605142
parent 156 ebd8a21a0e62
child 158 1b7ccb729164
Add aws s3 versioning and lifecycles to backup.
mercurial/aws-s3-backup/files/mercurial-s3-backup-lifecycle.json
mercurial/aws-s3-backup/files/mercurial-s3-backup.sh
mercurial/aws-s3-backup/tasks/main.yaml
pleroma/aws-s3-backup/files/pleroma-s3-backup-lifecycle.json
pleroma/aws-s3-backup/files/pleroma-s3-backup.sh
pleroma/aws-s3-backup/tasks/main.yaml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial/aws-s3-backup/files/mercurial-s3-backup-lifecycle.json	Sat Jul 03 13:24:52 2021 -0500
@@ -0,0 +1,12 @@
+{
+	 "Rules": [
+		  {
+				"ID": "pleroma-expiration",
+				"Filter": {},
+				"Status": "Enabled",
+				"NoncurrentVersionExpiration": {
+					 "NoncurrentDays": 30
+				}
+		  }
+	 ]
+}
--- a/mercurial/aws-s3-backup/files/mercurial-s3-backup.sh	Sat Jul 03 13:23:46 2021 -0500
+++ b/mercurial/aws-s3-backup/files/mercurial-s3-backup.sh	Sat Jul 03 13:24:52 2021 -0500
@@ -1,12 +1,13 @@
 #!/bin/bash
 
 BUCKET=$1
-DATE=`date --iso-8601`
 BACKUP_DIR=$2
-BACKUP_TAR="/tmp/$BUCKET-$DATE.tgz"
+BACKUP_TAR="/tmp/$BUCKET.tgz"
 
 tar -zc -f $BACKUP_TAR $BACKUP_DIR
 aws s3 mb "s3://$BUCKET/"
+aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
+aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration "file:///usr/local/share/mercurial-s3-backup-lifecycle.json"
 aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
 
 rm $BACKUP_TAR
--- a/mercurial/aws-s3-backup/tasks/main.yaml	Sat Jul 03 13:23:46 2021 -0500
+++ b/mercurial/aws-s3-backup/tasks/main.yaml	Sat Jul 03 13:24:52 2021 -0500
@@ -7,6 +7,13 @@
     dest: "/usr/local/bin/mercurial-s3-backup.sh"
     mode: "0755"
 
+- name: create s3 backup lifesycle json file
+  become: yes
+  copy:
+    src: "mercurial-s3-backup-lifecycle.json"
+    dest: "/usr/local/share/mercurial-s3-backup-lifecycle.json"
+    mode: "0755"
+
 - name: configure mercurial s3 backup systemd service
   become: yes
   template:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pleroma/aws-s3-backup/files/pleroma-s3-backup-lifecycle.json	Sat Jul 03 13:24:52 2021 -0500
@@ -0,0 +1,12 @@
+{
+	 "Rules": [
+		  {
+				"ID": "pleroma-expiration",
+				"Filter": {},
+				"Status": "Enabled",
+				"NoncurrentVersionExpiration": {
+					 "NoncurrentDays": 30
+				}
+		  }
+	 ]
+}
--- a/pleroma/aws-s3-backup/files/pleroma-s3-backup.sh	Sat Jul 03 13:23:46 2021 -0500
+++ b/pleroma/aws-s3-backup/files/pleroma-s3-backup.sh	Sat Jul 03 13:24:52 2021 -0500
@@ -1,11 +1,10 @@
 #!/bin/bash
 
 INSTANCE=$1
-DATE=`date --iso-8601`
 
 BUCKET="pleroma-${INSTANCE//_/-}-backup"
 BACKUP_DIR="/tmp/s3-backup/$BUCKET"
-BACKUP_TAR="/tmp/s3-backup/$BUCKET-$DATE.tgz"
+BACKUP_TAR="/tmp/s3-backup/$BUCKET.tgz"
 
 DB_NAME="pleroma_$INSTANCE"
 CONFIG="/etc/pleroma/$INSTANCE.config.exs"
@@ -23,6 +22,8 @@
 
 tar -zc -f $BACKUP_TAR $BACKUP_DIR
 aws s3 mb "s3://$BUCKET/"
+aws s3api put-bucket-versioning --bucket "$BUCKET" --versioning-configuration Status=Enabled
+aws s3api put-bucket-lifecycle-configuration --bucket "$BUCKET" --lifecycle-configuration "file:///usr/local/share/pleroma-s3-backup-lifecycle.json"
 aws s3 cp $BACKUP_TAR "s3://$BUCKET/"
 
 rm $BACKUP_TAR
--- a/pleroma/aws-s3-backup/tasks/main.yaml	Sat Jul 03 13:23:46 2021 -0500
+++ b/pleroma/aws-s3-backup/tasks/main.yaml	Sat Jul 03 13:24:52 2021 -0500
@@ -7,6 +7,13 @@
     dest: "/usr/local/bin/pleroma-s3-backup.sh"
     mode: "0755"
 
+- name: create s3 backup lifesycle json file
+  become: yes
+  copy:
+    src: "pleroma-s3-backup-lifecycle.json"
+    dest: "/usr/local/share/pleroma-s3-backup-lifecycle.json"
+    mode: "0755"
+
 - name: configure s3 backup systemd service
   become: yes
   copy: