lxd/db/containers.go
func (c *Cluster) ContainerBackupCreate(args ContainerBackupArgs) error {
	_, err := c.ContainerBackupID(args.Name)
	if err == nil {
		return ErrAlreadyDefined
	}

	err = c.Transaction(func(tx *ClusterTx) error {
		containerOnlyInt := 0
		if args.ContainerOnly {
			containerOnlyInt = 1
		}

		optimizedStorageInt := 0
		if args.OptimizedStorage {
			optimizedStorageInt = 1
		}

		str := fmt.Sprintf("INSERT INTO containers_backups (container_id, name, creation_date, expiry_date, container_only, optimized_storage) VALUES (?, ?, ?, ?, ?, ?)")
		stmt, err := tx.tx.Prepare(str)
		if err != nil {
			return err
		}
		defer stmt.Close()
		result, err := stmt.Exec(args.ContainerID, args.Name,
			args.CreationDate.Unix(), args.ExpiryDate.Unix(), containerOnlyInt,
			optimizedStorageInt)
		if err != nil {
			return err
		}

		_, err = result.LastInsertId()
		if err != nil {
			return fmt.Errorf("Error inserting %s into database", args.Name)
		}

		return nil
	})

	return err
}
func (c *Cluster) ContainerBackupCreate(args ContainerBackupArgs) error {
	_, err := c.ContainerBackupID(args.Name)
	if err == nil {
		return ErrAlreadyDefined
	}

	err = c.Transaction(func(tx *ClusterTx) error {
		containerOnlyInt := 0
		if args.ContainerOnly {
			containerOnlyInt = 1
		}

		optimizedStorageInt := 0
		if args.OptimizedStorage {
			optimizedStorageInt = 1
		}

		str := fmt.Sprintf("INSERT INTO containers_backups (container_id, name, creation_date, expiry_date, container_only, optimized_storage) VALUES (?, ?, ?, ?, ?, ?)")
		stmt, err := tx.tx.Prepare(str)
		if err != nil {
			return err
		}
		defer stmt.Close()
		result, err := stmt.Exec(args.ContainerID, args.Name,
			args.CreationDate.Unix(), args.ExpiryDate.Unix(), containerOnlyInt,
			optimizedStorageInt)
		if err != nil {
			return err
		}

		_, err = result.LastInsertId()
		if err != nil {
			return fmt.Errorf("Error inserting %s into database", args.Name)
		}

		return nil
	})

	return err
}
func ( c * Cluster ) ContainerBackupCreate ( args ContainerBackupArgs ) error { _ , err := c . ContainerBackupID ( args . Name ) if err == nil { return ErrAlreadyDefined } err = c . Transaction ( func ( tx * ClusterTx ) error { containerOnlyInt := 0 if args . ContainerOnly { containerOnlyInt = 1 } optimizedStorageInt := 0 if args . OptimizedStorage { optimizedStorageInt = 1 } str := fmt . Sprintf ( " " ) stmt , err := tx . tx . Prepare ( str ) if err != nil { return err } defer stmt . Close ( ) result , err := stmt . Exec ( args . ContainerID , args . Name , args . CreationDate . Unix ( ) , args . ExpiryDate . Unix ( ) , containerOnlyInt , optimizedStorageInt ) if err != nil { return err } _ , err = result . LastInsertId ( ) if err != nil { return fmt . Errorf ( " " , args . Name ) } return nil } ) return err }
// ContainerBackupCreate creates a new backup
ContainerBackupCreate creates a new backup