How to backup datastore via cron without datastore_admin? - google-app-engine

I have backuped datastore via cron using cron.yaml like following
- description: My Daily Backup
url: /_ah/datastore_admin/backup.create?name=BackupToCloud&kind=LogTitle&kind=EventLog&filesystem=gs&gs_bucket_name=whitsend
schedule: every 12 hours
target: ah-builtin-python-bundle
But
According to google announcement, datastore-admin will go to "deprecated".
https://cloud.google.com/datastore/docs/console/datastore-backing-up-restoring
How to backup datastore via cron without datastore_admin?
https://cloud.google.com/appengine/articles/scheduled_backups
says only about using gcloud.

Note that just the backup/restore functionality based on the datastore-admin will be deprecated, not the datastore-admin itself.
The deprecation note points to the Managed export and import service as the recommended replacement alternative.
Exports based on this method can also be scheduled, see Scheduling an Export. You'll note in that article that a standard env GAE app with a cron service is exactly what the method is based on.
The article is targeted at those apps using the Datastore outside of GAE. Since you already have a GAE app you can just modify your existing backup cron job handler following the example in the article or, if you want to separate it a bit from your main app, you can add a separate service to your app, dedicated to the backup cron job.

Related

Setting up Google App Engine cron job logs

I'm wondering how to set up logging for Google App Engine cron jobs. I haven't found any information about this specific topic in the App Engine documentation.
There's a page https://console.cloud.google.com/appengine/cronjobs in GCP. Every cron job has a "View" link in the "Log" column, which leads a user to the Logs Viewer with the following filters:
protoPayload.taskName="..."
protoPayload.taskQueueName="__cron"
In my case, no logs for cron jobs are displayed.
The service that serves the endpoints for the cron jobs is a node.js application that uses Winston logging with the transport provided by #google-cloud/logging-winston package. This application is responsible not only for processing cron jobs, and the logging works there fine: for instance, I'm able to filter specific queries by Google's trace id.
Is there anything I can provide with the logs payload to be able to filter them by taskName and taskQueueName? And where would I take these values, i.e. are there any request headers I could read them from and write with logs?
It would be great if it's something achievable with #google-cloud/logging-winston. If not, a library/language agnostic answer would also be helpful.

How to create a Cron Job in Google App Engine

I am new to Google App Engine, I am tring to create a cron job but I can't find where to start.
I create the App Engine => Task Queues => Cron Jobs and now I don't see an option to create one. Probably I missunderstand something very obvious, please help me to figure out what.
You need to create a new file - cron.yaml, describe your cron job in it, and upload it with the rest of the application as described in the documentation on Cron jobs for flexible environment.
Inside your applications directory, where your app.yaml is, you can create a file called cron.yaml to specify your cron jobs.

Cron per Service/Module (AppEngine)

I have two modules/services and each one has a cron.xml. Only one of these ever seems to run (the most recently deployed in my experience), and the other doesn't fail, but the endpoint is never triggered (never shows up in the logs).
Is there a 1-cron per project limit? What is the best way to manage crons so that modules aren't cross-dependant?
The cron.yaml is an app-level config file, not a service/module one. Meaning when you deploy the one you have in one module it'll overwrite the cron config from the other one.
So you have to create a single cron.yaml file containing job configs for all services/modules. As #GAEfan mentioned you'll also need add target configs for each job. You might also need to add a dispatch.yaml file and maybe re-visit/adjust the request paths so that the cron job-issued requests make it to the right service/module.
Deploying the app-level cron.yaml might not be happening implicitly when deploying the service(s), you may need to deploy it explicitly. From
Uploading cron jobs:
Option 2: Upload only your cron updates
To update just the cron configuration without uploading the rest of
the application, run the following command:
appcfg.py update_cron <app-directory>
Some more or less related Q&As:
Deploying different languages services to the same Application [Google App Engine]
Can a default service/module in a Google App Engine app be a sibling of a non-default one in terms of folder structure?
Use the target: backend-module-name parameter inside a cron job you want to send to a module other than default. Only one cron.yaml needed.
Make sure you update: appcfg.py update app.yaml backend_module.yaml cron.yaml

AppEngine Managed VMs Cron Job?

So I'm using an AE managed VM to host a website with the nodejs docker image - works great - site works, etc. However, I can't seem to get a AE cron job registered. I added a cron.yaml file right next to my app.yaml file, and I'm not excluding it in my docker file.
Is there some extra step I need to take for the cron job to be registered? Or are the cron jobs not supported on managed VMs?
Cron.yaml:
cron:
- description: daily summary job
url: /cron/socialmedia/twitter
schedule: every 2 minutes
At least on regular GAE (i.e. not managed VM) simply uploading the application with appcfg.py update doesn't always also update the cron jobs.
Updating cron jobs specifically, using appcfg.py update_cron should work in such cases.
You can deploy your cron.yaml jobs using gcloud preview app deploy cron.yaml

Programmatically modify cron schedule in Google App Engine

I am writing a wrapper around the Github Issues API to allow managers in my company to set up daily reminder emails to be sent to their devs. I want this to be configurable through an admin console, and give them the flexibility of setting up reminders at any time of day and any number of times a day.
The main App Engine cron system is configured statically through the cron.yaml file and cannot be changed by user action. Looking at the documentation it appears like I can only do this by reimplementing an entire cron infrastructure on top of the basic App Engine cron. Am I missing something? Is there anything like this that is already available elsewhere?
You are correct, you cannot setup programmatically the cron configuration.
You can configure a single cron which triggers a customized functions. This functions can read the configured crons (like datastore entities) and the launch different task based on your needs

Resources