Add datastore to snapshots, force Datastore display when jail exist on multi datastores
This commit is contained in:
@ -18,7 +18,6 @@ const (
|
||||
*******************************************************************************/
|
||||
func MigrateJail(args []string) {
|
||||
var jailNames []string
|
||||
var destDS Datastore
|
||||
|
||||
if len(args) > 0 {
|
||||
for _, a := range args {
|
||||
@ -27,26 +26,24 @@ func MigrateJail(args []string) {
|
||||
}
|
||||
|
||||
for _, jn := range jailNames {
|
||||
// Check if destination datastore exist
|
||||
found := false
|
||||
for _, ds := range gDatastores {
|
||||
if strings.EqualFold(gMigrateDestDatastore, ds.Name) {
|
||||
found = true
|
||||
destDS = ds
|
||||
break
|
||||
}
|
||||
}
|
||||
if false == found {
|
||||
fmt.Printf("Unkown datastore: %s\n", gMigrateDestDatastore)
|
||||
return
|
||||
}
|
||||
|
||||
cj, err := getJailFromArray(jn, gJails)
|
||||
if cj == nil {
|
||||
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if destination datastore exist & get current DS
|
||||
destDS, err := getDatastoreFromArray(gMigrateDestDatastore, gDatastores)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting datastore \"%s\": %v\n", gMigrateDestDatastore, err)
|
||||
return
|
||||
}
|
||||
curDS, err := getDatastoreFromArray(cj.Datastore, gDatastores)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting datastore \"%s\": %v\n", gMigrateDestDatastore, err)
|
||||
return
|
||||
}
|
||||
|
||||
if cj.Running == true && gYesToAll == false {
|
||||
fmt.Printf("WARNING: Jail %s is running\n", cj.Name)
|
||||
fmt.Printf("Migration will stop it for data sync before starting on the new pool. You will be prompted for shutdown.\n")
|
||||
@ -74,7 +71,7 @@ func MigrateJail(args []string) {
|
||||
*/
|
||||
|
||||
// Snapshot config
|
||||
dsconf := strings.Join([]string{cj.Zpool, "iocage", "jails", jn}, "/")
|
||||
dsconf := strings.Join([]string{curDS.ZFSDataset, "jails", jn}, "/")
|
||||
fmt.Printf("Snapshot %s: ", dsconf)
|
||||
if err = zfsSnapshot(dsconf, "gocage_mig_init"); err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
@ -83,7 +80,7 @@ func MigrateJail(args []string) {
|
||||
fmt.Printf("Done\n")
|
||||
|
||||
// Snapshot filesystem
|
||||
dsdata := strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/")
|
||||
dsdata := strings.Join([]string{curDS.ZFSDataset, "iocage", "jails", jn, "root"}, "/")
|
||||
fmt.Printf("Snapshot %s: ", dsdata)
|
||||
if err := zfsSnapshot(dsdata, "gocage_mig_init"); err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
@ -178,11 +175,14 @@ func CleanMigrateMess(args []string) error {
|
||||
for _, jn := range jailNames {
|
||||
cj, err := getJailFromArray(jn, gJails)
|
||||
if cj == nil {
|
||||
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
||||
return errors.New(fmt.Sprintf("Error getting jail %s: Not found\n", jn))
|
||||
}
|
||||
curDS, err := getDatastoreFromArray(cj.Datastore, gDatastores)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Error getting datastore \"%s\": %v\n", cj.Datastore, err))
|
||||
}
|
||||
|
||||
cmd := fmt.Sprintf("zfs destroy %s@gocage_mig_init", strings.Join([]string{cj.Zpool, "iocage", "jails", jn}, "/"))
|
||||
cmd := fmt.Sprintf("zfs destroy %s@gocage_mig_init", strings.Join([]string{curDS.ZFSDataset, "jails", jn}, "/"))
|
||||
out, err := executeCommand(cmd)
|
||||
if err != nil {
|
||||
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||
@ -190,7 +190,7 @@ func CleanMigrateMess(args []string) error {
|
||||
return errors.New(fmt.Sprintf("Error executing command %s: %v; command returned: %s\n", cmd, err, out))
|
||||
}
|
||||
}
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_init", strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/"))
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_init", strings.Join([]string{curDS.ZFSDataset, "jails", jn, "root"}, "/"))
|
||||
out, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||
@ -198,7 +198,7 @@ func CleanMigrateMess(args []string) error {
|
||||
return errors.New(fmt.Sprintf("Error executing command %s: %v; command returned: %s\n", cmd, err, out))
|
||||
}
|
||||
}
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_last_sync", strings.Join([]string{cj.Zpool, "iocage", "jails", jn}, "/"))
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_last_sync", strings.Join([]string{curDS.ZFSDataset, "jails", jn}, "/"))
|
||||
out, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||
@ -206,7 +206,7 @@ func CleanMigrateMess(args []string) error {
|
||||
return errors.New(fmt.Sprintf("Error executing command %s: %v; command returned: %s\n", cmd, err, out))
|
||||
}
|
||||
}
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_last_sync", strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/"))
|
||||
cmd = fmt.Sprintf("zfs destroy %s@gocage_mig_last_sync", strings.Join([]string{curDS.ZFSDataset, "jails", jn, "root"}, "/"))
|
||||
out, err = executeCommand(cmd)
|
||||
if err != nil {
|
||||
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||
|
Reference in New Issue
Block a user