github.com/gophercloud/gophercloud@v1.11.0/openstack/blockstorage/extensions/backups/doc.go (about)

     1  /*
     2  Package backups provides information and interaction with backups in the
     3  OpenStack Block Storage service. A backup is a point in time copy of the
     4  data contained in an external storage volume, and can be controlled
     5  programmatically.
     6  
     7  Example to List Backups
     8  
     9  	listOpts := backups.ListOpts{
    10  		VolumeID: "uuid",
    11  	}
    12  
    13  	allPages, err := backups.List(client, listOpts).AllPages()
    14  	if err != nil {
    15  		panic(err)
    16  	}
    17  
    18  	allBackups, err := backups.ExtractBackups(allPages)
    19  	if err != nil {
    20  		panic(err)
    21  	}
    22  
    23  	for _, backup := range allBackups {
    24  		fmt.Println(backup)
    25  	}
    26  
    27  Example to Create a Backup
    28  
    29  	createOpts := backups.CreateOpts{
    30  		VolumeID: "uuid",
    31  		Name:     "my-backup",
    32  	}
    33  
    34  	backup, err := backups.Create(client, createOpts).Extract()
    35  	if err != nil {
    36  		panic(err)
    37  	}
    38  
    39  	fmt.Println(backup)
    40  
    41  Example to Update a Backup
    42  
    43  	updateOpts := backups.UpdateOpts{
    44  		Name: "new-name",
    45  	}
    46  
    47  	backup, err := backups.Update(client, "uuid", updateOpts).Extract()
    48  	if err != nil {
    49  		panic(err)
    50  	}
    51  
    52  	fmt.Println(backup)
    53  
    54  Example to Restore a Backup to a Volume
    55  
    56  	options := backups.RestoreOpts{
    57  		VolumeID: "1234",
    58  		Name:     "vol-001",
    59  	}
    60  
    61  	restore, err := backups.RestoreFromBackup(client, "uuid", options).Extract()
    62  	if err != nil {
    63  		panic(err)
    64  	}
    65  
    66  	fmt.Println(restore)
    67  
    68  Example to Delete a Backup
    69  
    70  	err := backups.Delete(client, "uuid").ExtractErr()
    71  	if err != nil {
    72  		panic(err)
    73  	}
    74  
    75  Example to Export a Backup
    76  
    77  	export, err := backups.Export(client, "uuid").Extract()
    78  	if err != nil {
    79  		panic(err)
    80  	}
    81  
    82  	fmt.Println(export)
    83  
    84  Example to Import a Backup
    85  
    86  	status := "available"
    87  	availabilityZone := "region1b"
    88  	host := "cinder-backup-host1"
    89  	serviceMetadata := "volume_cf9bc6fa-c5bc-41f6-bc4e-6e76c0bea959/20200311192855/az_regionb_backup_b87bb1e5-0d4e-445e-a548-5ae742562bac"
    90  	size := 1
    91  	objectCount := 2
    92  	container := "my-test-backup"
    93  	service := "cinder.backup.drivers.swift.SwiftBackupDriver"
    94  	backupURL, _ := json.Marshal(backups.ImportBackup{
    95  		ID:               "d32019d3-bc6e-4319-9c1d-6722fc136a22",
    96  		Status:           &status,
    97  		AvailabilityZone: &availabilityZone,
    98  		VolumeID:         "cf9bc6fa-c5bc-41f6-bc4e-6e76c0bea959",
    99  		UpdatedAt:        time.Date(2020, 3, 11, 19, 29, 8, 0, time.UTC),
   100  		Host:             &host,
   101  		UserID:           "93514e04-a026-4f60-8176-395c859501dd",
   102  		ServiceMetadata:  &serviceMetadata,
   103  		Size:             &size,
   104  		ObjectCount:      &objectCount,
   105  		Container:        &container,
   106  		Service:          &service,
   107  		CreatedAt:        time.Date(2020, 3, 11, 19, 25, 24, 0, time.UTC),
   108  		DataTimestamp:    time.Date(2020, 3, 11, 19, 25, 24, 0, time.UTC),
   109  		ProjectID:        "14f1c1f5d12b4755b94edef78ff8b325",
   110  	})
   111  
   112  	options := backups.ImportOpts{
   113  		BackupService: "cinder.backup.drivers.swift.SwiftBackupDriver",
   114  		BackupURL:     backupURL,
   115  	}
   116  
   117  	backup, err := backups.Import(client, options).Extract()
   118  	if err != nil {
   119  		panic(err)
   120  	}
   121  
   122  	fmt.Println(backup)
   123  */
   124  package backups