Report this

What is the reason for this report?

Apply weekly backup plan to the servlet using API

Posted on April 8, 2025

Hello

I have a question about how to apply weekly backup plan to the servlets created automatically

 const droplet = await client.droplets.create({
            name: domain,
            region: 'ams3',
            size: 's-1vcpu-1gb',
            image: snapshot_id,
            ssh_keys: [await this.get_ssh_key()],
            backups: true,
            plan: 'weekly',
            ipv6: false,
            private_networking: true,
            volumes: null,
            tags: ['test'],
            user_data
        });
        

Field ‘plan’ doesn work in this context

Thank you …



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey @realmag777 👋

You’re almost there! The reason plan isn’t working is because it needs to be part of the backup_policy object, not a top-level field.

You can find that information in the API docs here:

https://docs.digitalocean.com/reference/api/digitalocean/#tag/Droplets/operation/droplets_create

Here’s how to update your code:

const droplet = await client.droplets.create({
  name: domain,
  region: 'ams3',
  size: 's-1vcpu-1gb',
  image: snapshot_id,
  ssh_keys: [await this.get_ssh_key()],
  backups: true,
  backup_policy: {
    plan: 'weekly',
    weekday: 'SUN',
    hour: 4
  },
  ipv6: false,
  private_networking: true,
  volumes: null,
  tags: ['test'],
  user_data
});

- Bobby

Heya, @realmag777

On top of what’s already mentioned, you can use the API to check the backup status like this:

const dropletInfo = await client.droplets.get(droplet.id); console.log(dropletInfo.backup_ids); // Will list backup IDs if enabled

Regards

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.