mirror of
https://github.com/jkaninda/mysql-bkup.git
synced 2025-12-06 05:29:41 +01:00
feat: add ftp backup storage
This commit is contained in:
@@ -80,7 +80,7 @@ func BackupTask(db *dbConfig, config *BackupConfig) {
|
||||
case "ssh", "remote":
|
||||
sshBackup(db, config)
|
||||
case "ftp":
|
||||
utils.Fatal("Not supported storage type: %s", config.storage)
|
||||
ftpBackup(db, config)
|
||||
default:
|
||||
localBackup(db, config)
|
||||
}
|
||||
@@ -190,7 +190,7 @@ func s3Backup(db *dbConfig, config *BackupConfig) {
|
||||
}
|
||||
utils.Info("Uploading backup archive to remote storage S3 ... ")
|
||||
utils.Info("Backup name is %s", finalFileName)
|
||||
err := utils.UploadFileToS3(tmpPath, finalFileName, bucket, s3Path)
|
||||
err := UploadFileToS3(tmpPath, finalFileName, bucket, s3Path)
|
||||
if err != nil {
|
||||
utils.Fatal("Error uploading file to S3: %s ", err)
|
||||
|
||||
@@ -204,7 +204,7 @@ func s3Backup(db *dbConfig, config *BackupConfig) {
|
||||
}
|
||||
// Delete old backup
|
||||
if config.prune {
|
||||
err := utils.DeleteOldBackup(bucket, s3Path, config.backupRetention)
|
||||
err := DeleteOldBackup(bucket, s3Path, config.backupRetention)
|
||||
if err != nil {
|
||||
utils.Fatal("Error deleting old backup from S3: %s ", err)
|
||||
}
|
||||
@@ -252,6 +252,41 @@ func sshBackup(db *dbConfig, config *BackupConfig) {
|
||||
//Delete temp
|
||||
deleteTemp()
|
||||
}
|
||||
func ftpBackup(db *dbConfig, config *BackupConfig) {
|
||||
utils.Info("Backup database to the remote FTP server")
|
||||
//Backup database
|
||||
BackupDatabase(db, config.backupFileName, disableCompression)
|
||||
finalFileName := config.backupFileName
|
||||
if config.encryption {
|
||||
encryptBackup(config.backupFileName, config.passphrase)
|
||||
finalFileName = fmt.Sprintf("%s.%s", config.backupFileName, "gpg")
|
||||
}
|
||||
utils.Info("Uploading backup archive to the remote FTP server ... ")
|
||||
utils.Info("Backup name is %s", finalFileName)
|
||||
err := CopyToFTP(finalFileName, config.remotePath)
|
||||
if err != nil {
|
||||
utils.Fatal("Error uploading file to the remote FTP server: %s ", err)
|
||||
|
||||
}
|
||||
|
||||
//Delete backup file from tmp folder
|
||||
err = utils.DeleteFile(filepath.Join(tmpPath, finalFileName))
|
||||
if err != nil {
|
||||
utils.Error("Error deleting file: %v", err)
|
||||
|
||||
}
|
||||
if config.prune {
|
||||
//TODO: Delete old backup from remote server
|
||||
utils.Info("Deleting old backup from a remote server is not implemented yet")
|
||||
|
||||
}
|
||||
|
||||
utils.Done("Uploading backup archive to the remote FTP server ... done ")
|
||||
//Send notification
|
||||
utils.NotifySuccess(finalFileName)
|
||||
//Delete temp
|
||||
deleteTemp()
|
||||
}
|
||||
|
||||
// encryptBackup encrypt backup
|
||||
func encryptBackup(backupFileName, passphrase string) {
|
||||
|
||||
Reference in New Issue
Block a user