Last active
May 26, 2020 08:40
-
-
Save athlona64/5f51084b14c76e99345a5e87c6728d5c to your computer and use it in GitHub Desktop.
autobackup&remove firestore
This file contains hidden or 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/bash | |
| now="$(date)" | |
| printf "Current date and time %s\n" "$now" | |
| now="$(date +'%d%m%Y')" | |
| printf "Current date in dd/mm/yyyy format %s\n" "$now" | |
| echo "Starting backup at $now, please wait..." | |
| /snap/bin/gcloud beta firestore export gs://backup-bucket/"$now" --collection-ids={collection in firestore can commas for multiple collections} | |
| #-15 day from today | |
| DATE="$(date --date="-15 day" "+%s")" | |
| echo $DATE | |
| echo "successfully backup !" | |
| ##ใส่ path ให้ถูกนะ | |
| list=`/snap/bin/gsutil -m ls -l gs://backup-bucket/` | |
| for f in $list | |
| do | |
| #this here up to range of bucket name your need to substring manual example gs://backup-bucket/04062020 | |
| # y=${f:23:4} you will get 2020 | |
| # m=${f:21:2} you will get 06 | |
| # d=${f:19:2} you will get 04 | |
| y=${f:{up to your path}:4} | |
| echo $y | |
| m=${f:{up to your path}:2} | |
| echo $m | |
| d=${f:{up to your path}:2} | |
| createDate="$(date -d "$y-$m-$d" "+%s")" | |
| echo $createDate | |
| if [[ "$createDate" < "$DATE" ]]; | |
| then | |
| echo "yes, starting remove $f" | |
| #remove older 15 days | |
| remove=`/snap/bin/gsutil -m rm -r "$f"` | |
| echo "remove $f succesfully" | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment