fix: restore uses absolute paths & better docs
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
10d5705d1a
commit
e421922f5b
|
@ -30,7 +30,7 @@ var appRestoreCommand = cli.Command{
|
||||||
Name: "restore",
|
Name: "restore",
|
||||||
Aliases: []string{"rs"},
|
Aliases: []string{"rs"},
|
||||||
Usage: "Run app restore",
|
Usage: "Run app restore",
|
||||||
ArgsUsage: "<domain> <service> <file> <path>",
|
ArgsUsage: "<domain> <service> <file>",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
},
|
},
|
||||||
|
@ -40,12 +40,17 @@ var appRestoreCommand = cli.Command{
|
||||||
This command runs an app restore.
|
This command runs an app restore.
|
||||||
|
|
||||||
Pre/post hook commands are defined in the recipe configuration. Abra reads this
|
Pre/post hook commands are defined in the recipe configuration. Abra reads this
|
||||||
config and run the comands in the context of the service before restoring the
|
configuration and run the comands in the context of the service before
|
||||||
backup.
|
restoring the backup.
|
||||||
|
|
||||||
|
Unlike "abra app backup", restore must be run on a per-service basis. You can
|
||||||
|
not restore all services in one go. Backup files produced by Abra are
|
||||||
|
compressed archives which use absolute paths. This allows Abra to restore
|
||||||
|
according to standard tar command logic.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
abra app restore example.com app mybackup.tar.gz /var/lib/content
|
abra app restore example.com app ~/.abra/backups/example_com_app_609341138.tar.gz
|
||||||
`,
|
`,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
|
@ -60,11 +65,6 @@ Example:
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("missing <file>?"))
|
internal.ShowSubcommandHelpAndError(c, errors.New("missing <file>?"))
|
||||||
}
|
}
|
||||||
|
|
||||||
restorePath := c.Args().Get(3)
|
|
||||||
if restorePath == "" {
|
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("missing <path>?"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := os.Stat(backupPath); err != nil {
|
if _, err := os.Stat(backupPath); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
logrus.Fatalf("%s doesn't exist?", backupPath)
|
logrus.Fatalf("%s doesn't exist?", backupPath)
|
||||||
|
@ -104,7 +104,7 @@ Example:
|
||||||
if !ok {
|
if !ok {
|
||||||
rsConfig = restoreConfig{}
|
rsConfig = restoreConfig{}
|
||||||
}
|
}
|
||||||
if err := runRestore(app, backupPath, restorePath, serviceName, rsConfig); err != nil {
|
if err := runRestore(app, backupPath, serviceName, rsConfig); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ Example:
|
||||||
}
|
}
|
||||||
|
|
||||||
// runRestore does the actual restore logic.
|
// runRestore does the actual restore logic.
|
||||||
func runRestore(app config.App, backupPath, restorePath, serviceName string, rsConfig restoreConfig) error {
|
func runRestore(app config.App, backupPath, serviceName string, rsConfig restoreConfig) error {
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -165,12 +165,16 @@ func runRestore(app config.App, backupPath, restorePath, serviceName string, rsC
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we use absolute paths so tar knows what to do. it will restore files
|
||||||
|
// according to the paths set in the compresed archive
|
||||||
|
restorePath := "/"
|
||||||
|
|
||||||
copyOpts := types.CopyToContainerOptions{AllowOverwriteDirWithFile: false, CopyUIDGID: false}
|
copyOpts := types.CopyToContainerOptions{AllowOverwriteDirWithFile: false, CopyUIDGID: false}
|
||||||
if err := cl.CopyToContainer(context.Background(), targetContainer.ID, restorePath, content, copyOpts); err != nil {
|
if err := cl.CopyToContainer(context.Background(), targetContainer.ID, restorePath, content, copyOpts); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("restored %s to %s:%s", backupPath, fullServiceName, restorePath)
|
logrus.Infof("restored %s to %s", backupPath, fullServiceName)
|
||||||
|
|
||||||
if rsConfig.postHookCmd != "" {
|
if rsConfig.postHookCmd != "" {
|
||||||
splitCmd := internal.SafeSplit(rsConfig.postHookCmd)
|
splitCmd := internal.SafeSplit(rsConfig.postHookCmd)
|
||||||
|
|
Loading…
Reference in New Issue