Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
Change upgrade procedure for 8.0.16
Browse files Browse the repository at this point in the history
ADJUSTMENTS
- Change upgrade procedure for MySQL 8.0.16+
- Adjust cookbook upgrade recipe to use verbose output
NEW FEATURES
- Add options --dry-run and --verbose to upgrade command
TESTING
- Enhance export tests
  • Loading branch information
datacharmer committed Apr 30, 2019
1 parent e9f40b7 commit 11e06c9
Show file tree
Hide file tree
Showing 13 changed files with 1,309 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .build/COMPATIBLE_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.26.0
1.29.0
2 changes: 1 addition & 1 deletion .build/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.28.2
1.29.0
8 changes: 8 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.29.0 30-Apr-2019
ADJUSTMENTS
- Change upgrade procedure for MySQL 8.0.16+
- Adjust cookbook upgrade recipe to use verbose output
NEW FEATURES
- Add options --dry-run and --verbose to upgrade command
TESTING
- Enhance export tests
1.28.2 22-Apr-2019
BUGS FIXED
- Add missing error checks
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[DBdeployer](https://github.com/datacharmer/dbdeployer) is a tool that deploys MySQL database servers easily.
This is a port of [MySQL-Sandbox](https://github.com/datacharmer/mysql-sandbox), originally written in Perl, and re-designed from the ground up in [Go](https://golang.org). See the [features comparison](https://github.com/datacharmer/dbdeployer/blob/master/docs/features.md) for more detail.

Documentation updated for version 1.28.0 (14-Apr-2019 14:17 UTC)
Documentation updated for version 1.29.0 (30-Apr-2019 17:41 UTC)

[![Build Status](https://travis-ci.org/datacharmer/dbdeployer.svg "Travis CI status")](https://travis-ci.org/datacharmer/dbdeployer)

Expand Down Expand Up @@ -48,7 +48,7 @@ Get the one for your O.S. from [dbdeployer releases](https://github.com/datachar

For example:

$ VERSION=1.28.0
$ VERSION=1.29.0
$ OS=linux
$ origin=https://github.com/datacharmer/dbdeployer/releases/download/v$VERSION
$ wget $origin/dbdeployer-$VERSION.$OS.tar.gz
Expand Down Expand Up @@ -83,7 +83,7 @@ For example:
The program doesn't have any dependencies. Everything is included in the binary. Calling *dbdeployer* without arguments or with ``--help`` will show the main help screen.

$ dbdeployer --version
dbdeployer version 1.28.0
dbdeployer version 1.29.0


$ dbdeployer -h
Expand Down Expand Up @@ -1106,7 +1106,9 @@ dbdeployer 1.10.0 introduces upgrades:
dbdeployer admin upgrade msb_8_0_11 msb_8_0_12

Flags:
-h, --help help for upgrade
--dry-run Shows upgrade operations, but don't execute them
-h, --help help for upgrade
--verbose Shows upgrade operations



Expand All @@ -1123,7 +1125,7 @@ dbdeployer checks all the conditions, then
2. renames the data directory of the newer version;
3. moves the data directory of the older version under the newer sandbox;
4. restarts the newer version;
5. runs ``mysql_upgrade``.
5. runs ``mysql_upgrade`` (except with MySQL 8.0.16+, where [https://mysqlserverteam.com/mysql-8-0-16-mysql_upgrade-is-going-away/](the server does the upgrade on its own)).

The older version is, at this point, not operational anymore, and can be deleted.

Expand Down Expand Up @@ -1376,18 +1378,18 @@ Should you need to compile your own binaries for dbdeployer, follow these steps:
1. Make sure you have go 1.10+ installed in your system, and that the ``$GOPATH`` variable is set.
2. Run ``go get -u github.com/datacharmer/dbdeployer``. This will import all the code that is needed to build dbdeployer.
3. Change directory to ``$GOPATH/src/github.com/datacharmer/dbdeployer``.
4. Run ``./scripts/build.sh {linux|OSX} 1.28.0``
5. If you need the docs enabled binaries (see the section "Generating additional documentation") run ``MKDOCS=1 ./scripts/build.sh {linux|OSX} 1.28.0``
4. Run ``./scripts/build.sh {linux|OSX} 1.29.0``
5. If you need the docs enabled binaries (see the section "Generating additional documentation") run ``MKDOCS=1 ./scripts/build.sh {linux|OSX} 1.29.0``

# Generating additional documentation

Between this file and [the API API list](https://github.com/datacharmer/dbdeployer/blob/master/docs/API/API-1.1.md), you have all the existing documentation for dbdeployer.
Should you need additional formats, though, dbdeployer is able to generate them on-the-fly. Tou will need the docs-enabled binaries: in the distribution list, you will find:

* dbdeployer-1.28.0-docs.linux.tar.gz
* dbdeployer-1.28.0-docs.osx.tar.gz
* dbdeployer-1.28.0.linux.tar.gz
* dbdeployer-1.28.0.osx.tar.gz
* dbdeployer-1.29.0-docs.linux.tar.gz
* dbdeployer-1.29.0-docs.osx.tar.gz
* dbdeployer-1.29.0.linux.tar.gz
* dbdeployer-1.29.0.osx.tar.gz

The executables containing ``-docs`` in their name have the same capabilities of the regular ones, but in addition they can run the *hidden* command ``tree``, with alias ``docs``.

Expand Down
90 changes: 75 additions & 15 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,21 @@ func unlockSandbox(cmd *cobra.Command, args []string) {
}
}

func upgradeSandbox(sandboxDir, oldSandbox, newSandbox string) error {
func DryRunCmdWithArgs(cmd string, args []string, dryRun bool) (string, error) {
if dryRun {
return "", nil
}
return common.RunCmdWithArgs(cmd, args)
}

func DryRunCmd(cmd string, dryRun bool) (string, error) {
if dryRun {
return "", nil
}
return common.RunCmd(cmd)
}

func upgradeSandbox(sandboxDir, oldSandbox, newSandbox string, verbose, dryRun bool) error {
var possibleUpgrades = map[string]string{
"5.0": "5.1",
"5.1": "5.5",
Expand All @@ -178,6 +192,12 @@ func upgradeSandbox(sandboxDir, oldSandbox, newSandbox string) error {
"5.7": "8.0",
"8.0": "8.0",
}
if dryRun {
verbose = true
}
if verbose {
fmt.Printf("cd %s\n", sandboxDir)
}
err := os.Chdir(sandboxDir)
common.ErrCheckExitf(err, 1, "can't change directory to %s", sandboxDir)
scripts := []string{globals.ScriptStart, globals.ScriptStop, globals.ScriptMy}
Expand Down Expand Up @@ -221,14 +241,20 @@ func upgradeSandbox(sandboxDir, oldSandbox, newSandbox string) error {
oldRev := oldVersionList[2]
newUpgradeVersion := fmt.Sprintf("%d.%d", newVersionList[0], newVersionList[1])
oldUpgradeVersion := fmt.Sprintf("%d.%d", oldVersionList[0], oldVersionList[1])
if oldMajor == 10 || newMajor == 10 {
if oldSbdesc.Flavor == common.MariaDbFlavor || newSbdesc.Flavor == common.MariaDbFlavor {
common.Exit(1, "upgrade from and to MariaDB is not supported")
}
greaterThanNewVersion, err := common.GreaterOrEqualVersionList(oldVersionList, newVersionList)
common.ErrCheckExitf(err, 1, globals.ErrWhileComparingVersions)
if greaterThanNewVersion {
common.Exitf(1, "version %s must be greater than %s", newUpgradeVersion, oldUpgradeVersion)
}

// 8.0.16
upgradeWithServer, err := common.HasCapability(newSbdesc.Flavor, common.UpgradeWithServer, newSbdesc.Version)
if err != nil {
return errors.Wrapf(err, "error detecting upgrade capability")
}
canBeUpgraded := false
if oldMajor < newMajor {
canBeUpgraded = true
Expand All @@ -242,42 +268,72 @@ func upgradeSandbox(sandboxDir, oldSandbox, newSandbox string) error {
}
}
if !canBeUpgraded {
return errors.Errorf("version '%s' can only be upgraded to '%s' or to the same version with a higher revision", oldUpgradeVersion, possibleUpgrades[oldUpgradeVersion])
return fmt.Errorf("version '%s' can only be upgraded to '%s' or to the same version with a higher revision", oldUpgradeVersion, possibleUpgrades[oldUpgradeVersion])
}
newSandboxOldData := path.Join(newSandbox, globals.DataDirName+"-"+newSandbox)
if common.DirExists(newSandboxOldData) {
return errors.Errorf("sandbox '%s' is already the upgrade from an older version", newSandbox)
return fmt.Errorf("sandbox '%s' is already the upgrade from an older version", newSandbox)
}
oldScriptStop := path.Join(oldSandbox, globals.ScriptStop)
if verbose {
fmt.Printf("# %s\n", oldScriptStop)
}
_, err = common.RunCmd(path.Join(oldSandbox, globals.ScriptStop))
_, err = DryRunCmd(oldScriptStop, dryRun)
if err != nil {
return errors.Wrapf(err, globals.ErrWhileStoppingSandbox, oldSandbox)
}
_, err = common.RunCmd(path.Join(newSandbox, globals.ScriptStop))
newScriptStop := path.Join(newSandbox, globals.ScriptStop)
if verbose {
fmt.Printf("# %s\n", newScriptStop)
}
_, err = DryRunCmd(newScriptStop, dryRun)
if err != nil {
return errors.Wrapf(err, globals.ErrWhileStoppingSandbox, newSandbox)
}
mvArgs := []string{path.Join(newSandbox, globals.DataDirName), newSandboxOldData}
_, err = common.RunCmdWithArgs("mv", mvArgs)
if verbose {
fmt.Printf("# mv %v\n", mvArgs)
}
_, err = DryRunCmdWithArgs("mv", mvArgs, dryRun)
if err != nil {
return errors.Wrapf(err, "error while moving data directory in sandbox %s", newSandbox)
}

mvArgs = []string{path.Join(oldSandbox, globals.DataDirName), path.Join(newSandbox, globals.DataDirName)}
_, err = common.RunCmdWithArgs("mv", mvArgs)
if verbose {
fmt.Printf("# mv %v\n", mvArgs)
}
_, err = DryRunCmdWithArgs("mv", mvArgs, dryRun)
if err != nil {
return errors.Wrapf(err, "error while moving data directory from sandbox %s to %s", oldSandbox, newSandbox)
}
common.CondPrintf("Data directory %s/data moved to %s/data \n", oldSandbox, newSandbox)

_, err = common.RunCmd(path.Join(newSandbox, globals.ScriptStart))
scriptStart := path.Join(newSandbox, globals.ScriptStart)
if upgradeWithServer {
if verbose {
fmt.Printf("# %s --upgrade=FORCE\n", scriptStart)
}
_, err = DryRunCmdWithArgs(scriptStart, []string{"--upgrade=FORCE"}, dryRun)
} else {
if verbose {
fmt.Printf("# %s\n", scriptStart)
}
_, err = DryRunCmd(scriptStart, dryRun)
}
if err != nil {
return errors.Wrapf(err, globals.ErrWhileStartingSandbox, newSandbox)
}
upgradeArgs := []string{"sql_upgrade"}
_, err = common.RunCmdWithArgs(path.Join(newSandbox, globals.ScriptMy), upgradeArgs)
if err != nil {

return errors.Wrapf(err, "error while running mysql_upgrade in %s", newSandbox)
if !upgradeWithServer {
upgradeArgs := []string{"sql_upgrade"}
scriptMy := path.Join(newSandbox, globals.ScriptMy)
if verbose {
fmt.Printf("# %s %v\n", scriptMy, upgradeArgs)
}
_, err = DryRunCmdWithArgs(scriptMy, upgradeArgs, dryRun)
if err != nil {
return errors.Wrapf(err, "error while running mysql_upgrade in %s", newSandbox)
}
}
fmt.Println("")
common.CondPrintf("The data directory from %s/data is preserved in %s\n", newSandbox, newSandboxOldData)
Expand All @@ -295,10 +351,12 @@ func runUpgradeSandbox(cmd *cobra.Command, args []string) {
oldSandbox := args[0]
newSandbox := args[1]
sandboxDir, err := getAbsolutePathFromFlag(cmd, "sandbox-home")
verbose, _ := cmd.Flags().GetBool(globals.VerboseLabel)
dryRun, _ := cmd.Flags().GetBool(globals.DryRunLabel)
if err != nil {
common.Exitf(1, "%+v", err)
}
err = upgradeSandbox(sandboxDir, oldSandbox, newSandbox)
err = upgradeSandbox(sandboxDir, oldSandbox, newSandbox, verbose, dryRun)
if err != nil {
common.Exitf(1, "%+v", err)
}
Expand Down Expand Up @@ -427,4 +485,6 @@ func init() {
adminCmd.AddCommand(adminUnlockCmd)
adminCmd.AddCommand(adminUpgradeCmd)
adminCmd.AddCommand(adminCapabilitiesCmd)
adminUpgradeCmd.Flags().BoolP(globals.VerboseLabel, "", false, "Shows upgrade operations")
adminUpgradeCmd.Flags().BoolP(globals.DryRunLabel, "", false, "Shows upgrade operations, but don't execute them")
}
Loading

0 comments on commit 11e06c9

Please sign in to comment.