Bugfix when "migrate clean" a jail which was already clean, code cleaning
This commit is contained in:
parent
31fa6904db
commit
6c6cb7edc8
@ -1,11 +1,11 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "os"
|
"os"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
/* "bufio"
|
"bufio"
|
||||||
"errors"
|
/* "errors"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
*/
|
*/
|
||||||
@ -21,7 +21,6 @@ const (
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
func MigrateJail(args []string) {
|
func MigrateJail(args []string) {
|
||||||
var jailNames []string
|
var jailNames []string
|
||||||
var cj *Jail
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
@ -30,6 +29,7 @@ func MigrateJail(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, jn := range jailNames {
|
for _, jn := range jailNames {
|
||||||
|
// Check if destination dataset exist
|
||||||
cmd := fmt.Sprintf("zfs list %s/iocage/jails", gMigrateDestPool)
|
cmd := fmt.Sprintf("zfs list %s/iocage/jails", gMigrateDestPool)
|
||||||
out, err := executeCommand(cmd)
|
out, err := executeCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -37,18 +37,24 @@ func MigrateJail(args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//cj, err := getJailFromArray(jn, gJails)
|
cj, err := getJailFromArray(jn, gJails)
|
||||||
for i, j := range gJails {
|
|
||||||
if strings.EqualFold(j.Name, jn) {
|
|
||||||
cj = &gJails[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cj == nil {
|
if cj == nil {
|
||||||
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cj.Running == true {
|
||||||
|
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")
|
||||||
|
fmt.Printf("Continue? (y/n) ")
|
||||||
|
scanr := bufio.NewScanner(os.Stdin)
|
||||||
|
scanr.Scan()
|
||||||
|
if false == strings.EqualFold(scanr.Text(), "y") {
|
||||||
|
fmt.Printf("Migration aborted\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO : Check dest pool (gMigrateDestPool) existence
|
/* TODO : Check dest pool (gMigrateDestPool) existence
|
||||||
zfs snapshot /iocage/jails/$jail@gocage_mig_first_snap
|
zfs snapshot /iocage/jails/$jail@gocage_mig_first_snap
|
||||||
zfs snapshot /iocage/jails/$jail/root@gocage_mig_first_snap
|
zfs snapshot /iocage/jails/$jail/root@gocage_mig_first_snap
|
||||||
@ -88,49 +94,6 @@ func MigrateJail(args []string) {
|
|||||||
}
|
}
|
||||||
fmt.Printf("Done\n")
|
fmt.Printf("Done\n")
|
||||||
|
|
||||||
/* // First, declare sending process & pipe
|
|
||||||
cmd_send = exec.Command("zfs", "send", fmt.Sprintf("%s@gocage_mig_init", strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/")))
|
|
||||||
stdout_send, err = cmd_send.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error executing command \"zfs send %s\": %v\n", fmt.Sprintf("%s@gocage_mig_init", strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/")), err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// then declare receiving process & pipe
|
|
||||||
cmd_recv = exec.Command("zfs", "receive", strings.Join([]string{gMigrateDestPool, "iocage", "jails", jn, "root"}, "/"))
|
|
||||||
stdin_recv, err = cmd_recv.StdinPipe()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error executing command \"zfs receive %s\": %v\n", strings.Join([]string{gMigrateDestPool, "iocage", "jails", jn, "root"}, "/"), err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy data in a go routine
|
|
||||||
go io.Copy(stdin_recv, stdout_send)
|
|
||||||
|
|
||||||
// then start processes and wait for finish
|
|
||||||
fmt.Printf("DEBUG: Start \"zfs receive %s\"\n", strings.Join([]string{gMigrateDestPool, "iocage", "jails", jn, "root"}, "/"))
|
|
||||||
if err := cmd_recv.Start(); err != nil {
|
|
||||||
fmt.Printf("Error starting zfs recv: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("DEBUG: Start \"zfs send %s\"\n", fmt.Sprintf("%s@gocage_mig_init", strings.Join([]string{cj.Zpool, "iocage", "jails", jn, "root"}, "/")))
|
|
||||||
if err := cmd_send.Start(); err != nil {
|
|
||||||
fmt.Printf("Error starting zfs send: %v\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("DEBUG: Wait for zfs send to finish\n")
|
|
||||||
if err := cmd_send.Wait(); err != nil {
|
|
||||||
fmt.Printf("Error: zfs send halted with %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("DEBUG: Wait for zfs recv to finish\n")
|
|
||||||
if err := cmd_recv.Wait(); err != nil {
|
|
||||||
fmt.Printf("Error: zfs recv halted with %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
dsdatadest := strings.Join([]string{gMigrateDestPool, "iocage", "jails", jn, "root"}, "/")
|
dsdatadest := strings.Join([]string{gMigrateDestPool, "iocage", "jails", jn, "root"}, "/")
|
||||||
fmt.Printf("Migrate jail filesystem dataset to %s: ", dsdatadest)
|
fmt.Printf("Migrate jail filesystem dataset to %s: ", dsdatadest)
|
||||||
if err := zfsCopy(fmt.Sprintf("%s@gocage_mig_init", dsdata), dsdatadest); err != nil {
|
if err := zfsCopy(fmt.Sprintf("%s@gocage_mig_init", dsdata), dsdatadest); err != nil {
|
||||||
@ -143,7 +106,6 @@ func MigrateJail(args []string) {
|
|||||||
// Clean snapshots from an aborted migration
|
// Clean snapshots from an aborted migration
|
||||||
func CleanMigrateMess(args []string) {
|
func CleanMigrateMess(args []string) {
|
||||||
var jailNames []string
|
var jailNames []string
|
||||||
var cj *Jail
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, a := range args {
|
for _, a := range args {
|
||||||
@ -152,12 +114,7 @@ func CleanMigrateMess(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, jn := range jailNames {
|
for _, jn := range jailNames {
|
||||||
for i, j := range gJails {
|
cj, err := getJailFromArray(jn, gJails)
|
||||||
if strings.EqualFold(j.Name, jn) {
|
|
||||||
cj = &gJails[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cj == nil {
|
if cj == nil {
|
||||||
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
fmt.Printf("Error getting jail %s: Not found\n", jn)
|
||||||
return
|
return
|
||||||
@ -166,7 +123,7 @@ func CleanMigrateMess(args []string) {
|
|||||||
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{cj.Zpool, "iocage", "jails", jn}, "/"))
|
||||||
out, err := executeCommand(cmd)
|
out, err := executeCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if false == strings.EqualFold(out, "could not find any snapshots to destroy; check snapshot names.") {
|
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||||
fmt.Printf("Error executing command %s: %v; command returned: %s\n", cmd, err, out)
|
fmt.Printf("Error executing command %s: %v; command returned: %s\n", cmd, err, out)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -174,7 +131,7 @@ func CleanMigrateMess(args []string) {
|
|||||||
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{cj.Zpool, "iocage", "jails", jn, "root"}, "/"))
|
||||||
out, err = executeCommand(cmd)
|
out, err = executeCommand(cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if false == strings.EqualFold(out, "could not find any snapshots to destroy; check snapshot names.") {
|
if false == strings.HasSuffix(out, "could not find any snapshots to destroy; check snapshot names.\n") {
|
||||||
fmt.Printf("Error executing command %s: %v; command returned: %s\n", cmd, err, out)
|
fmt.Printf("Error executing command %s: %v; command returned: %s\n", cmd, err, out)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user