Skip to content

Commit

Permalink
Add COPY_ONLY flag in backup options (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Anisur Rahman <[email protected]>
  • Loading branch information
anisurrahman75 authored Aug 8, 2024
1 parent 74ac388 commit f894e8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/sqlserver/backup_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const backupPushShortDescription = "Creates new backup and pushes it to the stor

var backupPushDatabases []string
var backupUpdateLatest bool
var copyOnly bool

var backupPushCmd = &cobra.Command{
Use: "backup-push",
Short: backupPushShortDescription,
Run: func(cmd *cobra.Command, args []string) {
internal.ConfigureLimiters()
sqlserver.HandleBackupPush(backupPushDatabases, backupUpdateLatest)
sqlserver.HandleBackupPush(backupPushDatabases, backupUpdateLatest, copyOnly)
},
}

Expand All @@ -25,5 +26,7 @@ func init() {
"List of databases to backup. All not-system databases as default")
backupPushCmd.PersistentFlags().BoolVarP(&backupUpdateLatest, "update-latest", "u", false,
"Update latest backup instead of creating new one")
backupPushCmd.PersistentFlags().BoolVarP(&copyOnly, "copy-only", "c", false,
"Backup with COPY_ONLY option")
cmd.AddCommand(backupPushCmd)
}
9 changes: 6 additions & 3 deletions internal/databases/sqlserver/backup_push_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/wal-g/wal-g/utility"
)

func HandleBackupPush(dbnames []string, updateLatest bool) {
func HandleBackupPush(dbnames []string, updateLatest, copyOnly bool) {
ctx, cancel := context.WithCancel(context.Background())
signalHandler := utility.NewSignalHandler(ctx, cancel, []os.Signal{syscall.SIGINT, syscall.SIGTERM})
defer func() { _ = signalHandler.Close() }()
Expand Down Expand Up @@ -56,7 +56,7 @@ func HandleBackupPush(dbnames []string, updateLatest bool) {
}
builtinCompression := blob.UseBuiltinCompression()
err = runParallel(func(i int) error {
return backupSingleDatabase(ctx, db, backupName, dbnames[i], builtinCompression)
return backupSingleDatabase(ctx, db, backupName, dbnames[i], builtinCompression, copyOnly)
}, len(dbnames), getDBConcurrency())
tracelog.ErrorLogger.FatalfOnError("overall backup failed: %v", err)

Expand All @@ -71,7 +71,7 @@ func HandleBackupPush(dbnames []string, updateLatest bool) {
tracelog.InfoLogger.Printf("backup finished")
}

func backupSingleDatabase(ctx context.Context, db *sql.DB, backupName string, dbname string, builtinCompression bool) error {
func backupSingleDatabase(ctx context.Context, db *sql.DB, backupName string, dbname string, builtinCompression, copyOnlyBackup bool) error {
baseURL := getDatabaseBackupURL(backupName, dbname)
size, blobCount, err := estimateDBSize(db, dbname)
if err != nil {
Expand All @@ -84,6 +84,9 @@ func backupSingleDatabase(ctx context.Context, db *sql.DB, backupName string, db
if builtinCompression {
sql += ", COMPRESSION"
}
if copyOnlyBackup {
sql += ", COPY_ONLY"
}
tracelog.InfoLogger.Printf("starting backup database [%s] to %s", dbname, urls)
tracelog.DebugLogger.Printf("SQL: %s", sql)
_, err = db.ExecContext(ctx, sql)
Expand Down

0 comments on commit f894e8b

Please sign in to comment.