Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- package.json
- {
- "name": "sample-cloud-storage",
- "version": "0.0.1",
- "dependencies": {
- "@google-cloud/storage": "1.2.1"
- }
- }
- /**
- * Triggered from a message on a Cloud Storage bucket.
- *
- * @param {!Object} event The Cloud Functions event.
- * @param {!Function} The callback function.
- */
- const Storage = require('@google-cloud/storage');
- exports.backupTerraformState = function(event, callback) {
- const storage = Storage();
- const file = event.data;
- console.log(file.name);
- var d = new Date();
- var patt = /^[a-zA-Z_-]*terraform\.tfstat$/;
- if (file.name.str.match(patt)) {
- storage
- .bucket(file.bucket)
- .file(file.name)
- .copy(storage.bucket("my-terraform-bucket").file("backup/" + file.name+ "-" + Math.round(Date.now() / 1000) ))
- .then(() => {
- console.log("copied");
- })
- .catch((err) => {
- console.error('ERROR:', err);
- });
- } else {
- console.log("not match:[" + file.name + "]");
- }
- callback();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement