瀏覽代碼

maybea buld

Fred Damstra (k8s1) 2 年之前
父節點
當前提交
15a89e4c6e
共有 5 個文件被更改,包括 19 次插入96 次删除
  1. 1 1
      Dockerfile
  2. 5 7
      README.md
  3. 11 0
      aws-backup.sh
  4. 2 2
      kaniko-aws-backup.yaml
  5. 0 86
      update-route53.sh

+ 1 - 1
Dockerfile

@@ -14,6 +14,6 @@ RUN apt-get update \
 
 COPY . /opt/update-route53
 RUN chmod 755 /opt/update-route53/update-route53.sh \
- && mkdir /scratch
+ && mkdir /source
 
 CMD ["/opt/update-route53/update-route53.sh"]

+ 5 - 7
README.md

@@ -1,10 +1,10 @@
-# update_route53
+# aws-backup
 
-Update the monkeybox IP in aws
+Sync a source directory to s3 in aws
 
-## Mount a volume to /scratch
+## Mount a volume to /source
 
-This is used to store the last IP and the log
+This is what you want to backup.
 
 ## Create a set of environment variable secrets
 
@@ -19,9 +19,7 @@ kubectl create secret generic update-route53 \
 
 ## you must set the following env variables
 
-`ZONEID` - Hosted Zone ID e.g. BJBK35SKMM9OE
-
-`RECORDSET` - The CNAME you want to update e.g. hello.example.com
+`DEST_S3` the destination URL to sync to. `s3://` expected.
 
 `AWS_ACCESS_KEY_ID`
 `AWS_SECRET_ACCESS_KEY`

+ 11 - 0
aws-backup.sh

@@ -0,0 +1,11 @@
+#! /bin/bash
+
+if [[ ! -v DEST_S3 ]]; then
+  echo "Must specify DEST_S3 as an env variable"
+  exit -1
+fi
+
+aws s3 sync /source ${DEST_S3} \
+        --delete \
+        --exclude gogs/gogs/log/* \
+        --exclude gogs/gogs/data/sessions/*

+ 2 - 2
kaniko-update-route53.yaml → kaniko-aws-backup.yaml

@@ -27,8 +27,8 @@ spec:
         image: gcr.io/kaniko-project/executor:v1.9.1 
         args:
         - "--dockerfile=./Dockerfile"
-        - "--context=git://git.monkeybox.org/Containers/update-route53#refs/heads/master"
-        - "--destination=fdamstra/update-route53:latest"
+        - "--context=git://git.monkeybox.org/Containers/aws-backup#refs/heads/main"
+        - "--destination=fdamstra/aws-backup:latest"
         env:
           - name: GIT_TOKEN
             valueFrom:

+ 0 - 86
update-route53.sh

@@ -1,86 +0,0 @@
-#!/bin/bash
- 
-# More advanced options below
-# The Time-To-Live of this recordset
-TTL=300
-# Change this if you want
-COMMENT="Auto updating @ `date`"
-# Change to AAAA if using an IPv6 address
-TYPE="A"
- 
-# Get the external IP address
-IP=`curl -ss http://ipv4.icanhazip.com/`
- 
-function valid_ip()
-{
-    local  ip=$1
-    local  stat=1
- 
-    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
-        OIFS=$IFS
-        IFS='.'
-        ip=($ip)
-        IFS=$OIFS
-        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
-            && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
-        stat=$?
-    fi
-    return $stat
-}
-
-DIR=/scratch/
-LOGFILE="$DIR/update-route53.log"
-IPFILE="$DIR/update-route53.ip"
- 
-if ! valid_ip $IP; then
-    echo "Invalid IP address: $IP" | tee -a "$LOGFILE"
-    exit 1
-fi
- 
-# Check if the IP has changed
-if [ ! -f "$IPFILE" ]
-    then
-    touch "$IPFILE"
-fi
- 
-if grep -Fxq "$IP" "$IPFILE"; then
-    # code if found
-    echo "IP is still $IP. Exiting" | tee -a "$LOGFILE"
-    exit 0
-else
-    echo "IP has changed to $IP" | tee -a "$LOGFILE"
-    # Fill a temp file with valid JSON
-    TMPFILE=$(mktemp /tmp/temporary-file.XXXXXXXX)
-    cat > ${TMPFILE} << EOF
-    {
-      "Comment":"$COMMENT",
-      "Changes":[
-        {
-          "Action":"UPSERT",
-          "ResourceRecordSet":{
-            "ResourceRecords":[
-              {
-                "Value":"$IP"
-              }
-            ],
-            "Name":"$RECORDSET",
-            "Type":"$TYPE",
-            "TTL":$TTL
-          }
-        }
-      ]
-    }
-EOF
- 
-    # Update the Hosted Zone record
-    aws route53 change-resource-record-sets \
-        --hosted-zone-id $ZONEID \
-        --change-batch file://"$TMPFILE" | tee -a "$LOGFILE"
-    echo "" | tee -a "$LOGFILE"
- 
-    # Clean up
-    rm $TMPFILE
-fi
- 
-# All Done - cache the IP address for next time
-echo "$IP" > "$IPFILE"