Creating a disk snapshot schedule
Configuring an automatic disk snapshot schedule
To configure automatic scheduled creation of disk snapshots:
-
In the management console
, select the folder containing the disk. -
Select Compute Cloud.
-
In the left-hand panel, select
Snapshots. -
In the Snapshot schedules tab, click Create.
-
Configure schedule parameters:
-
Enter a name for the schedule in the following format:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
If required, provide a free-form text description for the schedule.
-
Select disks for which you need to create scheduled snapshots. One schedule can include several disks and one disk can be added to several schedules within the limits.
You can create snapshots of network drives, such as HDDs, SSDs, and non-replicated SSDs, as well as ultra-high performance network storages with three replicas (SSD).
For non-replicated SSDs and ultra-high performance network storages with three replicas (SSD), the snapshot time is not determined.
To take snapshots of local disks residing on dedicated hosts, use Yandex Cloud Backup. This service supports Ubuntu, CentOS, CentOS Stream, and Windows Server.
-
In the Create snapshots field, select how often the snapshots will be created:
By hour
,By day
,By week
, orBy cron expression
. The snapshot creation time is specified in UTC±00:00 . -
In the Starting on field, set the start date for your schedule.
-
Select the snapshot retention policy:
- Store all snapshots: All the snapshots created according to this schedule will be retained.
- Only the last: Set the number of the last snapshots to be retained or the number of days for which the snapshots are to be retained. Other snapshots created according to this schedule will be deleted automatically.
Note
Quotas apply to the number and total amount of snapshots in the cloud.
-
-
Click Create.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI commands for managing schedules:
yc compute snapshot-schedule --help yc compute snapshot-schedule create --help
-
Create a schedule using a cron expression:
yc compute snapshot-schedule create <schedule_name> \ --expression <cron_expression>
Note
The snapshot creation time is specified in UTC±00:00
.If you need to configure a snapshot retention policy, add the
--snapshot-count
or--retention-period
parameter, for example:--snapshot-count 5
: Retain 5 latest snapshots.--retention-period 72h
: Retain snapshots for the last 3 days.
To add the start date for a schedule, use the
--start-at
parameter, For example:--start-at "2022-12-31T16:39:00+05:00"
: Schedule starts at 16:39 UTC+5 on December 31, 2022.--start-at "2h"
: Schedule starts two hours before the current time point.
For more information about the
yc compute snapshot-schedule create
command, see the CLI reference. -
To add disks to the schedule, get disk IDs:
yc compute disk list --format yaml
Result:
- id: epdcq9g3co9s******** folder_id: e1ea8s8l71li******** created_at: "2022-10-13T14:37:44Z" ... instance_ids: - fhm1c7u23aiq******** disk_placement_policy: {}
-
Add disks to the schedule:
yc compute snapshot-schedule add-disks <schedule_name_or_ID> \ --disk-id <disk_1_ID>,<disk_2_ID>
Result:
done (3s) id: fc8e52mvchb2******** folder_id: e1ea8s8l71li******** ... expression: 36 14 */1 * * snapshot_count: "3" snapshot_spec: {}
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the Terraform configuration file, describe the parameters of the resource to create:
resource "yandex_compute_snapshot_schedule" "default" { name = "<schedule_name>" schedule_policy { expression = "<cron_expression>" } snapshot_count = <number_of_snapshots_for_each_disk> snapshot_spec { description = "<snapshot_description>" labels = { <snapshot_label_key> = "<snapshot_label_value>" } } disk_ids = ["<disk_1_ID>", "<disk_2_ID>"] }
Where:
name
: Schedule name. This is a required parameter.schedule_policy
: Section with schedule parameters. It contains theexpression
field with a cron expression. This is a required parameter.snapshot_count
: Maximum number of snapshots per disk. This is an optional parameter.snapshot_spec
: Section with additional snapshot parameters. This is an optional parameter. It may contain the following fields:description
: Snapshot description.labels
: Snapshot label in<key> = "<value>"
format.
disk_ids
: IDs of disks to create snapshots for. This is a required parameter.
For more information about the
yandex_compute_snapshot_schedule
resource parameters in Terraform, see the relevant provider documentation . -
Create resources:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
This will create a schedule in the specified folder. You can check the new schedule and its settings using the management console
yc compute snapshot-schedule get <schedule_name>
-
Get the list of disks using the list REST API method for the Disk resource or the DiskService/List gRPC API call.
You can create snapshots of network drives, such as HDDs, SSDs, and non-replicated SSDs, as well as ultra-high performance network storages with three replicas (SSD).
For non-replicated SSDs and ultra-high performance network storages with three replicas (SSD), the snapshot time is not determined.
To take snapshots of local disks residing on dedicated hosts, use Yandex Cloud Backup. This service supports Ubuntu, CentOS, CentOS Stream, and Windows Server.
-
Create a snapshot schedule using the create REST API method for the SnapshotSchedule resource or the SnapshotScheduleService/Create gRPC API call.
Snapshots are created and deleted automatically only while the schedule is on (has the ACTIVE
status).
Examples
Snapshots are created every day
To set up daily creation of snapshots:
-
Create a schedule using a cron expression:
yc compute snapshot-schedule create sched-1 \ --description "Daily" \ --expression "10 16 ? * *" \ --start-at "2022-12-31T19:04:05+03:00" \ --snapshot-count 7 \ --labels "machine=file-server"
As a result, the following schedule is created:
- Name:
sched-1
; description:Daily
. - Snapshots taken daily at 19:10 Moscow time.
- Start date: December 31 at 19:04 Moscow time.
- Last seven snapshots retained.
- Label:
machine
; label value:file-server
.
- Name:
-
Get disk IDs to add them to the schedule:
yc compute disk list --format yaml
Result:
- id: epdcq9g3co9s******** folder_id: e1ea8s8l71li******** created_at: "2022-10-13T14:37:44Z" name: disk-2 type_id: network-hdd zone_id: ru-central1-a size: "21474836480" block_size: "4096" product_ids: - f2euv1kekdgv******** status: READY source_image_id: fd88d14a6790******** instance_ids: - ephothb6lppn******** disk_placement_policy: {} - id: fhm7mip40dqh******** folder_id: e1ea8s8l71li******** created_at: "2022-10-10T05:00:04Z" name: disk-1 type_id: network-hdd zone_id: ru-central1-a size: "21474836480" block_size: "4096" product_ids: - f2euv1kekdgv******** status: READY source_image_id: fd88d14a6790******** instance_ids: - fhm1c7u23aiq******** disk_placement_policy: {}
-
Add disks to the schedule:
yc compute snapshot-schedule add-disks sched-1 \ --disk-id epdcq9g3co9s********,fhm7mip40dqh********
Result:
done (3s) id: fc8bplhqmh2b******** folder_id: e1ea8s8l71li******** created_at: "2022-10-03T13:28:01Z" name: sched-1 description: Daily labels: machine: file-server status: ACTIVE schedule_policy: start_at: "2022-12-31T16:04:05Z" expression: 10 16 ? * * snapshot_count: "7" snapshot_spec: {}