forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Greenplum backup push (wal-g#992)
* [WIP] add greenplum backup-push command * [WIP] fix GetGreenplumSegmentsInfo query * [WIP] fix queries * [WIP] cleanup * [WIP] fix * [WIP] add port to command * [WIP] fix backupNamePrefix flag * fix postgres backup name regexp * fix extracting backup names * fix connection to segments * fix extracting backups for backup-list * add logging * fix delta backup * add test * fix test * included test into CI * fix lint * fix * fix comments * Revert backup prefix logic * Refactor args handling * change wal-g docker binary name * Remove unused stuff && fix linter complaints * Add config path specification * Add wal-g output to debug * Implement single config per host Add WALG_STORAGE_PREFIX config option Remove -c shorthand to avoid confusion with --config Remove backup-push argument in docker test * Add config option to tests && fix linter error * Update go.mod && go.sum Co-authored-by: nastprol <[email protected]> Co-authored-by: usernamedt <[email protected]>
- Loading branch information
1 parent
d0c3e66
commit 5f14deb
Showing
31 changed files
with
804 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package gp | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/wal-g/wal-g/internal/databases/greenplum" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
) | ||
|
||
const ( | ||
backupPushShortDescription = "Makes backup and uploads it to storage" | ||
|
||
permanentFlag = "permanent" | ||
fullBackupFlag = "full" | ||
verifyPagesFlag = "verify" | ||
storeAllCorruptBlocksFlag = "store-all-corrupt" | ||
useRatingComposerFlag = "rating-composer" | ||
addUserDataFlag = "add-user-data" | ||
|
||
permanentShorthand = "p" | ||
fullBackupShorthand = "f" | ||
verifyPagesShorthand = "v" | ||
storeAllCorruptBlocksShorthand = "s" | ||
useRatingComposerShorthand = "r" | ||
) | ||
|
||
var ( | ||
// backupPushCmd represents the backupPush command | ||
backupPushCmd = &cobra.Command{ | ||
Use: "backup-push", | ||
Short: backupPushShortDescription, // TODO : improve description | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if userData == "" { | ||
userData = viper.GetString(internal.SentinelUserDataSetting) | ||
} | ||
|
||
arguments := greenplum.NewBackupArguments(permanent, userData, prepareSegmentFwdArgs()) | ||
backupHandler, err := greenplum.NewBackupHandler(arguments) | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
backupHandler.HandleBackupPush() | ||
}, | ||
} | ||
permanent = false | ||
userData = "" | ||
|
||
// as for now, WAL-G will simply forward these arguments to the segments | ||
// todo: handle delta-from-name and delta-from-userdata | ||
fullBackup = false | ||
verifyPageChecksums = false | ||
storeAllCorruptBlocks = false | ||
useRatingComposer = false | ||
) | ||
|
||
// prepare arguments that are going to be forwarded to segments | ||
func prepareSegmentFwdArgs() []greenplum.SegmentFwdArg { | ||
verifyPageChecksums = verifyPageChecksums || viper.GetBool(internal.VerifyPageChecksumsSetting) | ||
storeAllCorruptBlocks = storeAllCorruptBlocks || viper.GetBool(internal.StoreAllCorruptBlocksSetting) | ||
useRatingComposer = useRatingComposer || viper.GetBool(internal.UseRatingComposerSetting) | ||
|
||
return []greenplum.SegmentFwdArg{ | ||
{Name: fullBackupFlag, Value: strconv.FormatBool(fullBackup)}, | ||
} | ||
} | ||
|
||
func init() { | ||
cmd.AddCommand(backupPushCmd) | ||
|
||
backupPushCmd.Flags().BoolVarP(&permanent, permanentFlag, permanentShorthand, | ||
false, "Pushes permanent backup") | ||
backupPushCmd.Flags().BoolVarP(&fullBackup, fullBackupFlag, fullBackupShorthand, | ||
false, "Make full backup-push") | ||
backupPushCmd.Flags().BoolVarP(&verifyPageChecksums, verifyPagesFlag, verifyPagesShorthand, | ||
false, "Verify page checksums") | ||
backupPushCmd.Flags().BoolVarP(&storeAllCorruptBlocks, storeAllCorruptBlocksFlag, storeAllCorruptBlocksShorthand, | ||
false, "Store all corrupt blocks found during page checksum verification") | ||
backupPushCmd.Flags().BoolVarP(&useRatingComposer, useRatingComposerFlag, useRatingComposerShorthand, | ||
false, "Use rating tar composer (beta)") | ||
backupPushCmd.Flags().StringVar(&userData, addUserDataFlag, | ||
"", "Write the provided user data to the backup sentinel and metadata files.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package gp | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/wal-g/tracelog" | ||
"github.com/wal-g/wal-g/internal" | ||
) | ||
|
||
var dbShortDescription = "GreenplumDB backup tool" | ||
|
||
// These variables are here only to show current version. They are set in makefile during build process | ||
var walgVersion = "devel" | ||
var gitRevision = "devel" | ||
var buildDate = "devel" | ||
|
||
var cmd = &cobra.Command{ | ||
Use: "wal-g", | ||
Short: dbShortDescription, // TODO : improve description | ||
Version: strings.Join([]string{walgVersion, gitRevision, buildDate, "GreenplumDB"}, "\t"), | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
err := internal.AssertRequiredSettingsSet() | ||
tracelog.ErrorLogger.FatalOnError(err) | ||
}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). | ||
func Execute() { | ||
if err := cmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
internal.ConfigureSettings(internal.GP) | ||
cobra.OnInitialize(internal.InitConfig, internal.Configure) | ||
|
||
cmd.PersistentFlags().StringVar(&internal.CfgFile, "config", "", "config file (default is $HOME/.wal-g.yaml)") | ||
_ = cmd.MarkFlagRequired("config") // config is required for Greenplum WAL-G | ||
cmd.InitDefaultVersionFlag() | ||
internal.AddConfigFlags(cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
FROM wal-g/ubuntu:latest | ||
|
||
RUN apt-get update && \ | ||
apt-get install --yes --no-install-recommends --no-install-suggests locales iputils-ping ssh python-dev iproute2 less sudo \ | ||
gnupg \ | ||
gpg-agent \ | ||
pinentry-qt \ | ||
time \ | ||
bc \ | ||
jq | ||
|
||
WORKDIR /usr/local | ||
RUN git clone https://github.com/greenplum-db/gpdb.git gpdb_src | ||
|
||
RUN ./gpdb_src/concourse/scripts/setup_gpadmin_user.bash | ||
|
||
WORKDIR /usr/local/gpdb_src | ||
RUN locale-gen en_US.utf8 | ||
RUN ./README.Ubuntu.bash | ||
|
||
WORKDIR /usr/local/gpdb_src | ||
RUN ./configure --with-perl --with-python --with-libxml --with-gssapi --prefix=/usr/local/gpdb_src > /dev/nul && \ | ||
make -j8 > /dev/nul && \ | ||
make -j8 install > /dev/null | ||
|
||
ADD docker/gp/run_greenplum.sh /home/gpadmin/run_greenplum.sh | ||
|
||
RUN chown gpadmin:gpadmin /home/gpadmin/run_greenplum.sh \ | ||
&& chmod a+x /home/gpadmin/run_greenplum.sh \ | ||
&& echo "export MASTER_DATA_DIRECTORY=/usr/local/gpdb_src/gpAux/gpdemo/datadirs/qddir/demoDataDir-1" > /home/gpadmin/.bash_profile \ | ||
&& echo "source /usr/local/gpdb_src/greenplum_path.sh" > /home/gpadmin/.bash_profile \ | ||
&& chown gpadmin:gpadmin /home/gpadmin/.bash_profile | ||
|
||
RUN echo "gpadmin ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \ | ||
&& echo "root ALL=NOPASSWD: ALL" >> /etc/sudoers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
sudo /etc/init.d/ssh start | ||
|
||
. /usr/local/gpdb_src/greenplum_path.sh | ||
|
||
cd /usr/local/gpdb_src | ||
|
||
/usr/local/gpdb_src/bin/gpssh-exkeys -h `hostname` | ||
|
||
make create-demo-cluster | ||
|
||
. /usr/local/gpdb_src/gpAux/gpdemo/gpdemo-env.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
FROM wal-g/golang:latest as build | ||
|
||
WORKDIR /go/src/github.com/wal-g/wal-g | ||
|
||
RUN apt-get update && \ | ||
apt-get install --yes --no-install-recommends --no-install-suggests | ||
|
||
COPY go.mod go.mod | ||
COPY vendor/ vendor/ | ||
COPY internal/ internal/ | ||
COPY cmd/ cmd/ | ||
COPY main/ main/ | ||
COPY utility/ utility/ | ||
COPY Makefile Makefile | ||
|
||
|
||
RUN sed -i 's|#cgo LDFLAGS: -lbrotli.*|&-static -lbrotlicommon-static -lm|' \ | ||
vendor/github.com/google/brotli/go/cbrotli/cgo.go && \ | ||
cd main/gp && \ | ||
go build -mod vendor -tags brotli -race -o wal-g -ldflags "-s -w -X main.buildDate=`date -u +%Y.%m.%d_%H:%M:%S`" | ||
|
||
RUN make gp_build | ||
|
||
RUN cd main/pg && \ | ||
go build -mod vendor -tags brotli -race -o wal-g -ldflags "-s -w -X main.buildDate=`date -u +%Y.%m.%d_%H:%M:%S`" | ||
|
||
RUN make pg_build | ||
|
||
FROM wal-g/gp:latest | ||
|
||
USER root | ||
|
||
COPY docker/pg/PGP_KEY /tmp/PGP_KEY | ||
COPY docker/pg/gpg.conf /home/gpadmin/.gnupg/gpg.conf | ||
COPY docker/pg/gpg-agent.conf /home/gpadmin/.gnupg/gpg-agent.conf | ||
|
||
COPY --from=build /go/src/github.com/wal-g/wal-g/main/gp/wal-g /usr/bin/wal-g-gp | ||
COPY --from=build /go/src/github.com/wal-g/wal-g/main/pg/wal-g /usr/bin | ||
|
||
COPY docker/gp_tests/scripts/ /tmp | ||
COPY docker/pg_tests/scripts/scripts/ /tmp/pg_scripts | ||
|
||
RUN chmod 777 /tmp/configs/ | ||
|
||
RUN /bin/bash -c 'sudo chmod +x -R /tmp/tests; chmod +x /tmp/run_integration_tests.sh' | ||
|
||
CMD su gpadmin bash -c '/tmp/run_integration_tests.sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", | ||
"PGSSLMODE": "allow", | ||
"WALG_NETWORK_RATE_LIMIT": "10485760", | ||
"WALG_DISK_RATE_LIMIT": "41943040", | ||
"AWS_ACCESS_KEY_ID": "AKIAIOSFODNN7EXAMPLE", | ||
"WALG_UPLOAD_CONCURRENCY": "10", | ||
"AWS_ENDPOINT": "http://s3:9000", | ||
"PGDATABASE": "postgres", | ||
"AWS_S3_FORCE_PATH_STYLE": "true", | ||
"WALG_COMPRESSION_METHOD": "brotli" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"WALE_S3_PREFIX": "s3://gpfullbucket", | ||
"WALG_DELTA_MAX_STEPS": "6", | ||
"WALG_PGP_KEY_PATH": "/tmp/PGP_KEY", | ||
"WALG_LOG_LEVEL": "DEVEL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
set -e -x | ||
|
||
pushd /tmp | ||
for i in tests/*.sh; do | ||
echo | ||
echo "===== RUNNING $i =====" | ||
set -x | ||
./"$i"; | ||
|
||
set +x | ||
echo "===== SUCCESS $i =====" | ||
echo | ||
done | ||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -e -x | ||
|
||
CONFIG_FILE="/tmp/configs/full_backup_test_config.json" | ||
COMMON_CONFIG="/tmp/configs/common_config.json" | ||
TMP_CONFIG="/tmp/configs/tmp_config.json" | ||
cat ${CONFIG_FILE} > ${TMP_CONFIG} | ||
echo "," >> ${TMP_CONFIG} | ||
cat ${COMMON_CONFIG} >> ${TMP_CONFIG} | ||
/tmp/pg_scripts/wrap_config_file.sh ${TMP_CONFIG} | ||
|
||
/home/gpadmin/run_greenplum.sh | ||
|
||
source /usr/local/gpdb_src/gpAux/gpdemo/gpdemo-env.sh && /usr/local/gpdb_src/bin/createdb | ||
sleep 10 | ||
|
||
wal-g-gp backup-push --config=${TMP_CONFIG} | ||
|
||
echo "Greenplum backup-push test was successful" |
Oops, something went wrong.