Skip to content

Commit

Permalink
Merge pull request #58 from uselagoon/fix/pipe-to-mysqldump-exit-error
Browse files Browse the repository at this point in the history
replacing pipe to gzip with an initial dump, then gzip it
  • Loading branch information
Tim Clifford authored Jul 28, 2022
2 parents b515b6c + ff639b1 commit 1ec0e65
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions synchers/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package synchers
import (
"errors"
"fmt"
"path/filepath"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -140,8 +141,11 @@ func (root MariadbSyncRoot) GetRemoteCommand(sourceEnvironment Environment) Sync
tablesWhoseDataToIgnore += fmt.Sprintf("--ignore-table-data=%s.%s ", m.DbDatabase, s)
}

//We remove the `.gz` from the transfer resource name for because we _first_ generate a plain `.sql` file
//and _then_ gzip it
resourceNameWithoutGz := strings.TrimSuffix(transferResource.Name, filepath.Ext(transferResource.Name))
return SyncCommand{
command: fmt.Sprintf("mysqldump {{ .dumpOptions }} -h{{ .hostname }} -u{{ .username }} -p{{ .password }} -P{{ .port }} {{ .tablesToIgnore }} {{ .database }} | gzip -c | cat > {{ .transferResource }}"),
command: fmt.Sprintf("mysqldump {{ .dumpOptions }} -h{{ .hostname }} -u{{ .username }} -p{{ .password }} -P{{ .port }} {{ .tablesToIgnore }} {{ .database }} > {{ .transferResource }} && gzip {{ .transferResource }}"),
substitutions: map[string]interface{}{
"dumpOptions": "--max-allowed-packet=500M --quick --add-locks --no-autocommit --single-transaction",
"hostname": m.DbHostname,
Expand All @@ -150,7 +154,7 @@ func (root MariadbSyncRoot) GetRemoteCommand(sourceEnvironment Environment) Sync
"port": m.DbPort,
"tablesToIgnore": tablesWhoseDataToIgnore,
"database": m.DbDatabase,
"transferResource": transferResource.Name,
"transferResource": resourceNameWithoutGz,
},
}
}
Expand All @@ -161,7 +165,7 @@ func (m MariadbSyncRoot) GetLocalCommand(targetEnvironment Environment) SyncComm
l = m.getEffectiveLocalDetails()
}
transferResource := m.GetTransferResource(targetEnvironment)
return generateSyncCommand("gunzip < {{ .transferResource }} | mysql -h{{ .hostname }} -u{{ .username }} -p{{ .password }} -P{{ .port }} {{ .database }}",
return generateSyncCommand("mysql -h{{ .hostname }} -u{{ .username }} -p{{ .password }} -P{{ .port }} {{ .database }} < <(gunzip < {{ .transferResource }})",
map[string]interface{}{
"hostname": l.DbHostname,
"username": l.DbUsername,
Expand Down

0 comments on commit 1ec0e65

Please sign in to comment.