How to create and rotate Automatic Snapshot?

前端 未结 10 2040
梦如初夏
梦如初夏 2020-12-14 08:33

On Compute Engine we can do Snapshots, which are basically backups. Could you try to figure out how we could create a script to do automated snapshots every day and keep lik

10条回答
  •  粉色の甜心
    2020-12-14 08:55

    If nothing else I know that [--set-scheduling] is a situational gcloud flag and there's a wait [process] that will prevent the current command from executing until that process is complete. Combine that with && operator (executes same-statement commands after the previous is completed), stringing this sucker together shouldn't be too hard. Just run it at startup (when you create an instance it has startup command option) and have it count time or make one of the regular maintenance functions trigger the commands. But honestly, why mix syntax if you don't have to?

    This could work (don't copy/paste)

    gcloud config set compute/zone wait [datetime-function] && \
    gcloud compute disks snapshot snap1 snap2 snap3 \
            --snapshot-names ubuntu12 ubuntu14 debian8  \
            --description=\
                '--format="multi(\
                    info:format=list always-display-title compact,\
                    data:format=list always-display-title compact\
                    )"'
    

    In theory gcloud will set the compute/zone but will have to wait until the time specified. Because of the double ampersand (&&) the next command will not execute until after the first command is complete. I may have gone overboard on the description but I did so for the sake of showing the simplicity of it, I know it won't work as is but I also know I'm not that far off. Wow after looking at all the code one might believe we're attempting to solve the immortality sequence. I don't think working it out in a bash file is the best way. gcloud made command line for people that don't know command line. We've been taught (or learned... or haven't learned yet) to write code a proper way relative to the environment. I say we apply that here and use the CLOUD SDK to our advantage.

提交回复
热议问题