Skip to content

Commit 40557af

Browse files
authored
Merge pull request #130 from jkaninda/refactor
Refactor
2 parents c16ee3a + 1dcb958 commit 40557af

File tree

13 files changed

+44
-11
lines changed

13 files changed

+44
-11
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ TZ=Europe/Paris
2727

2828
### Backup Cron Expression
2929
#BACKUP_CRON_EXPRESSION=@midnight
30+
##Delete old backup created more than specified days ago
31+
#BACKUP_RETENTION_DAYS=7
3032

3133
####SSH Storage
3234
#SSH_HOST_NAME=

cmd/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var BackupCmd = &cobra.Command{
2020
if len(args) == 0 {
2121
pkg.StartBackup(cmd)
2222
} else {
23-
utils.Fatal("Error, no argument required")
23+
utils.Fatal(`"backup" accepts no argument %q`, args)
2424
}
2525
},
2626
}

cmd/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var MigrateCmd = &cobra.Command{
1919
if len(args) == 0 {
2020
pkg.StartMigration(cmd)
2121
} else {
22-
utils.Fatal("Error, no argument required")
22+
utils.Fatal(`"migrate" accepts no argument %q`, args)
2323

2424
}
2525

cmd/restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var RestoreCmd = &cobra.Command{
1414
if len(args) == 0 {
1515
pkg.StartRestore(cmd)
1616
} else {
17-
utils.Fatal("Error, no argument required")
17+
utils.Fatal(`"restore" accepts no argument %q`, args)
1818

1919
}
2020

docs/how-tos/backup-to-s3.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ services:
7474
- AWS_ACCESS_KEY=xxxx
7575
- AWS_SECRET_KEY=xxxxx
7676
# - BACKUP_CRON_EXPRESSION=0 1 * * * # Optional
77+
#Delete old backup created more than specified days ago
78+
#- BACKUP_RETENTION_DAYS=7
7779
## In case you are using S3 alternative such as Minio and your Minio instance is not secured, you change it to true
7880
- AWS_DISABLE_SSL="false"
7981
# mysql-bkup container must be connected to the same network with your database

docs/how-tos/backup-to-ssh.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ services:
7979
- REMOTE_PATH=/home/jkaninda/backups
8080
- SSH_IDENTIFY_FILE=/tmp/id_ed25519
8181
# - BACKUP_CRON_EXPRESSION=0 1 * * * # Optional
82+
#Delete old backup created more than specified days ago
83+
#- BACKUP_RETENTION_DAYS=7
8284
## We advise you to use a private jey instead of password
8385
#- SSH_PASSWORD=password
8486
# mysql-bkup container must be connected to the same network with your database

docs/how-tos/backup.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ services:
7575
- DB_USERNAME=username
7676
- DB_PASSWORD=password
7777
- BACKUP_CRON_EXPRESSION=0 1 * * *
78+
#Delete old backup created more than specified days ago
79+
#- BACKUP_RETENTION_DAYS=7
7880
# mysql-bkup container must be connected to the same network with your database
7981
networks:
8082
- web

docs/reference/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ Backup, restore and migrate targets, schedule and retention are configured using
2626
| --dbname | -d | Database name |
2727
| --port | -p | Database port (default: 3306) |
2828
| --disable-compression | | Disable database backup compression |
29-
| --prune | | Delete old backup, default disabled |
30-
| --keep-last | | Delete old backup created more than specified days ago, default 7 days |
3129
| --cron-expression | | Backup cron expression, eg: (* * * * *) or @daily |
3230
| --help | -h | Print this help message and exit |
3331
| --version | -V | Print version information and exit |
@@ -52,6 +50,7 @@ Backup, restore and migrate targets, schedule and retention are configured using
5250
| GPG_PASSPHRASE | Optional, required to encrypt and restore backup | GPG passphrase |
5351
| GPG_PUBLIC_KEY | Optional, required to encrypt backup | GPG public key, used to encrypt backup (/config/public_key.asc) |
5452
| BACKUP_CRON_EXPRESSION | Optional if it was provided from the `--cron-expression` flag | Backup cron expression for docker in scheduled mode |
53+
| BACKUP_RETENTION_DAYS | Optional | Delete old backup created more than specified days ago |
5554
| SSH_HOST | Optional, required for SSH storage | ssh remote hostname or ip |
5655
| SSH_USER | Optional, required for SSH storage | ssh remote user |
5756
| SSH_PASSWORD | Optional, required for SSH storage | ssh remote user's password |

pkg/backup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func StartBackup(cmd *cobra.Command) {
4646
func scheduledMode(db *dbConfig, config *BackupConfig) {
4747
utils.Info("Running in Scheduled mode")
4848
utils.Info("Backup cron expression: %s", config.cronExpression)
49+
utils.Info("The next scheduled time is: %v", utils.CronNextTime(config.cronExpression).Format(timeFormat))
4950
utils.Info("Storage type %s ", config.storage)
5051

5152
//Test backup
@@ -58,6 +59,8 @@ func scheduledMode(db *dbConfig, config *BackupConfig) {
5859

5960
_, err := c.AddFunc(config.cronExpression, func() {
6061
BackupTask(db, config)
62+
utils.Info("Next backup time is: %v", utils.CronNextTime(config.cronExpression).Format(timeFormat))
63+
6164
})
6265
if err != nil {
6366
return
@@ -119,6 +122,7 @@ func startMultiBackup(bkConfig *BackupConfig, configFile string) {
119122
if utils.IsValidCronExpression(bkConfig.cronExpression) {
120123
utils.Info("Running MultiBackup in Scheduled mode")
121124
utils.Info("Backup cron expression: %s", bkConfig.cronExpression)
125+
utils.Info("The next scheduled time is: %v", utils.CronNextTime(bkConfig.cronExpression).Format(timeFormat))
122126
utils.Info("Storage type %s ", bkConfig.storage)
123127

124128
//Test backup
@@ -132,6 +136,8 @@ func startMultiBackup(bkConfig *BackupConfig, configFile string) {
132136
_, err := c.AddFunc(bkConfig.cronExpression, func() {
133137
// Create a channel
134138
multiBackupTask(conf.Databases, bkConfig)
139+
utils.Info("Next backup time is: %v", utils.CronNextTime(bkConfig.cronExpression).Format(timeFormat))
140+
135141
})
136142
if err != nil {
137143
return

pkg/config.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ func initAWSConfig() *AWSConfig {
172172
func initBackupConfig(cmd *cobra.Command) *BackupConfig {
173173
utils.SetEnv("STORAGE_PATH", storagePath)
174174
utils.GetEnv(cmd, "cron-expression", "BACKUP_CRON_EXPRESSION")
175-
utils.GetEnv(cmd, "period", "BACKUP_CRON_EXPRESSION")
176175
utils.GetEnv(cmd, "path", "REMOTE_PATH")
177176
//Get flag value and set env
178177
remotePath := utils.GetEnvVariable("REMOTE_PATH", "SSH_REMOTE_PATH")

0 commit comments

Comments
 (0)