Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementation of operations to manage MongoDB backups: - stream-push - stream-fetch - oplog-push - delete - backup-list * Added docker configuration and integration tests for push commands * make subfolder for oplog.bson to restore more comfortable * integration test for delete command * Integration tests improvements: -test oplog deletion -remove oplog dump dir after test * move HandleStreamFetch and DownloadAndDecompressStream to internal helper * descriptions of internal functions * -race option for build in docker
- Loading branch information
Showing
29 changed files
with
847 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package mongo | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/tracelog" | ||
) | ||
|
||
const BackupListShortDescription = "Prints available backups" | ||
|
||
// backupListCmd represents the backupList command | ||
var backupListCmd = &cobra.Command{ | ||
Use: "backup-list", | ||
Short: BackupListShortDescription, // TODO : improve description | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
internal.HandleBackupList(folder) | ||
}, | ||
} | ||
|
||
func init() { | ||
MongoCmd.AddCommand(backupListCmd) | ||
} |
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,71 @@ | ||
package mongo | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/storages/storage" | ||
"github.com/wal-g/wal-g/internal/tracelog" | ||
"github.com/wal-g/wal-g/utility" | ||
) | ||
|
||
var confirmed = false | ||
|
||
// deleteCmd represents the delete command | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Clears old backups and oplog", | ||
} | ||
|
||
var deleteBeforeCmd = &cobra.Command{ | ||
Use: "before backup_name|timestamp", // TODO : improve description | ||
Example: internal.DeleteBeforeExamples, | ||
Args: internal.DeleteBeforeArgsValidator, | ||
Run: runDeleteBefore, | ||
} | ||
|
||
var deleteRetainCmd = &cobra.Command{ | ||
Use: "retain backup_count", // TODO : improve description | ||
Example: internal.DeleteRetainExamples, | ||
ValidArgs: internal.StringModifiers, | ||
Args: internal.DeleteRetainArgsValidator, | ||
Run: runDeleteRetain, | ||
} | ||
|
||
func runDeleteBefore(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
|
||
internal.HandleDeleteBefore(folder, args, confirmed, isFullBackup, GetLessFunc(folder)) | ||
} | ||
|
||
func runDeleteRetain(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
|
||
internal.HandleDeleteRetain(folder, args, confirmed, isFullBackup, GetLessFunc(folder)) | ||
} | ||
|
||
func isFullBackup(object storage.Object) bool { | ||
return true | ||
} | ||
|
||
func init() { | ||
MongoCmd.AddCommand(deleteCmd) | ||
deleteCmd.AddCommand(deleteBeforeCmd, deleteRetainCmd) | ||
deleteCmd.PersistentFlags().BoolVar(&confirmed, internal.ConfirmFlag, false, "Confirms backup deletion") | ||
} | ||
|
||
func GetLessFunc(folder storage.Folder) func(object1, object2 storage.Object) bool { | ||
return func(object1, object2 storage.Object) bool { | ||
time1, ok1 := utility.TryFetchTimeRFC3999(object1.GetName()) | ||
time2, ok2 := utility.TryFetchTimeRFC3999(object2.GetName()) | ||
if !ok1 || !ok2 { | ||
return object2.GetLastModified().After(object1.GetLastModified()) | ||
} | ||
return time1 < time2 | ||
} | ||
} |
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,37 @@ | ||
package mongo | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/wal-g/wal-g/internal" | ||
) | ||
|
||
var MongoDBShortDescription = "MongoDB 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 MongoCmd = &cobra.Command{ | ||
Use: "wal-g", | ||
Short: MongoDBShortDescription, // TODO : improve description | ||
Version: strings.Join([]string{WalgVersion, GitRevision, BuildDate, "MongoDB"}, "\t"), | ||
} | ||
|
||
func Execute() { | ||
if err := MongoCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(internal.InitConfig, internal.Configure) | ||
|
||
MongoCmd.PersistentFlags().StringVar(&internal.CfgFile, "config", "", "config file (default is $HOME/.wal-g.yaml)") | ||
MongoCmd.InitDefaultVersionFlag() | ||
} |
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,29 @@ | ||
package mongo | ||
|
||
import ( | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/databases/mongo" | ||
"github.com/wal-g/wal-g/internal/tracelog" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const oplogPushShortDescription = "" | ||
|
||
// oplogPushCmd represents the cron command | ||
var oplogPushCmd = &cobra.Command{ | ||
Use: "oplog-push", | ||
Short: oplogPushShortDescription, | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
uploader, err := internal.ConfigureUploader() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
mongo.HandleOplogPush(&mongo.Uploader{Uploader: uploader}) | ||
}, | ||
} | ||
|
||
func init() { | ||
MongoCmd.AddCommand(oplogPushCmd) | ||
} |
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,29 @@ | ||
package mongo | ||
|
||
import ( | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/databases/mongo" | ||
"github.com/wal-g/wal-g/internal/tracelog" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const StreamFetchShortDescription = "" | ||
|
||
// streamFetchCmd represents the streamFetch command | ||
var streamFetchCmd = &cobra.Command{ | ||
Use: "stream-fetch backup-name", | ||
Short: StreamFetchShortDescription, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
folder, err := internal.ConfigureFolder() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
internal.HandleStreamFetch(args[0], folder, mongo.FetchBackupStreamAndOplog) | ||
}, | ||
} | ||
|
||
func init() { | ||
MongoCmd.AddCommand(streamFetchCmd) | ||
} |
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,28 @@ | ||
package mongo | ||
|
||
import ( | ||
"github.com/wal-g/wal-g/internal" | ||
"github.com/wal-g/wal-g/internal/databases/mongo" | ||
"github.com/wal-g/wal-g/internal/tracelog" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const StreamPushShortDescription = "" | ||
|
||
// streamPushCmd represents the streamPush command | ||
var streamPushCmd = &cobra.Command{ | ||
Use: "stream-push", | ||
Short: StreamPushShortDescription, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
uploader, err := internal.ConfigureUploader() | ||
if err != nil { | ||
tracelog.ErrorLogger.FatalError(err) | ||
} | ||
mongo.HandleStreamPush(&mongo.Uploader{Uploader: uploader}) | ||
}, | ||
} | ||
|
||
func init() { | ||
MongoCmd.AddCommand(streamPushCmd) | ||
} |
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,6 @@ | ||
FROM wal-g/ubuntu:latest | ||
|
||
RUN apt-get update -y | ||
RUN apt-get install mongodb -y | ||
|
||
COPY docker/mongo/mongodb.conf /etc/mongodb.conf |
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,17 @@ | ||
# mongodb.conf | ||
|
||
# Where to store the data. | ||
dbpath=/var/lib/mongodb | ||
|
||
#where to log | ||
logpath=/var/log/mongodb/mongodb.log | ||
|
||
logappend=true | ||
|
||
bind_ip = 127.0.0.1 | ||
#port = 27017 | ||
|
||
journal=true | ||
|
||
master = true | ||
|
Oops, something went wrong.