Skip to content

Commit

Permalink
Add readme and removed count option
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Anarase <[email protected]>
  • Loading branch information
Vishal Anarase committed Jan 31, 2024
1 parent 11ac765 commit 917217d
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 12 deletions.
2 changes: 0 additions & 2 deletions cmd/database/database_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

var name, schedule, backupType string
var count int

// dbBackupCmd is the root command for the db backup subcommand
var dbBackupCmd = &cobra.Command{
Expand All @@ -32,7 +31,6 @@ func init() {
// Create cmd options
dbBackupCreateCmd.Flags().StringVarP(&name, "name", "n", "", "name of the database backup")
dbBackupCreateCmd.Flags().StringVarP(&schedule, "schedule", "s", "", "schedule of the database backup in the form of cronjob")
dbBackupCreateCmd.Flags().IntVarP(&count, "count", "c", 1, "number of backups to keep")
dbBackupCreateCmd.Flags().StringVarP(&backupType, "type", "t", "scheduled", "set the type of database backup manual/scheduled")

dbBackupCreateCmd.MarkFlagRequired("name")
Expand Down
9 changes: 1 addition & 8 deletions cmd/database/database_backup_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var dbBackupCreateCmd = &cobra.Command{
Use: "create",
Aliases: []string{"new", "add"},
Example: `Scheduled: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --schedule <SCHEDULE> --count <COUNT>\n
Example: `Scheduled: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --schedule <SCHEDULE>\n
Manual: civo database backup create <DATABASE-NAME/ID> --name <BACKUP_NAME> --type manual`,
Short: "Create a new database backup",
Args: cobra.MinimumNArgs(1),
Expand Down Expand Up @@ -51,11 +51,6 @@ var dbBackupCreateCmd = &cobra.Command{
client.Region = common.RegionSet
}

if count <= 0 {
utility.Error("Count must be greater than zero, you have given: %d", count)
os.Exit(1)
}

if schedule == "" {
utility.Error("Schedule must be specified")
os.Exit(1)
Expand All @@ -69,8 +64,6 @@ var dbBackupCreateCmd = &cobra.Command{

backupCreateConfig.Name = name
backupCreateConfig.Schedule = schedule
backupCreateConfig.Count = int32(count)

} else {
backupCreateConfig.Name = name
backupCreateConfig.Type = backupType
Expand Down
4 changes: 2 additions & 2 deletions cmd/database/database_backup_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var dbBackupUpdateCmd = &cobra.Command{
client.Region = common.RegionSet
}

if schedule == "" && count == 0 && name == "" {
utility.Error("Schedule, name or count must be specified")
if schedule == "" && name == "" {
utility.Error("Schedule, name must be specified")
os.Exit(1)
}

Expand Down
150 changes: 150 additions & 0 deletions doc/DTABASE_BACKUP_RESTORE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

# Database Backup and Restore

> This repository provides a solution for backing up and restoring databases. Whether you need scheduled backups for automated routine tasks or manual backups for specific events, this guide will walk you through the process.
## Backup Types

### Scheduled Backups

Scheduled backups are automated processes that run at predefined intervals. They help ensure that your data is regularly backed up without manual intervention.

To set up scheduled backups, follow the steps outlined in the Configuration section.

* Support: PostgreSQL

### Manual Backups

Manual backups are initiated by a user on-demand. These are useful for creating backups before system updates, major changes, or any event that requires a snapshot of the database at a specific point in time.

To manually create a backup, follow the steps outlined in the Usage section.

* Support: PostgreSQL, MySQL

### Restore Process

The restore process allows you to recover your database from a previously created backup.

* Support: PostgreSQL, MySQL

# CLI Operations

## Create MySQL and PostgreSQL database

```bash
❯ ./civo --config staging.civo.json database create postgres-demo --size g3.db.medium --software PostgreSQL --version 14
Database (postgres-demo) with ID 65dd8173-f754-4c6c-b50a-7ddb6d5446c5 has been created
```

```bash
❯ ./civo --config staging.civo.json database create mysql-demo --size g3.db.medium --software MySQL --version 8.0
Database (mysql-demo) with ID 0d328d59-98c3-4f68-8025-5b1633a1c287 has been created
```

```bash
❯ ./civo --config staging.civo.json database ls
+--------+---------------+--------------+-------+------------+------------------+--------------+------+--------+
| ID | Name | Size | Nodes | Software | Software Version | Host | Port | Status |
+--------+---------------+--------------+-------+------------+------------------+--------------+------+--------+
| 65dd81 | postgres-demo | g3.db.medium | 1 | PostgreSQL | 14 | 31.28.88.149 | 5432 | Ready |
+--------+---------------+--------------+-------+------------+------------------+--------------+------+--------+
| 0d328d | mysql-demo | g3.db.medium | 1 | MySQL | 8.0 | 31.28.88.184 | 3306 | Ready |
+--------+---------------+--------------+-------+------------+------------------+--------------+------+--------+
To get the credentials for a database, use `civo db credential <name/ID>`
```

### List database backups

```bash
❯ ./civo --config staging.civo.json database backups ls postgres-demo
❯ ./civo --config staging.civo.json database backups ls mysql-demo
```

## PostgreSQL

### Create Scheduled Backup

```bash
❯ ./civo --config staging.civo.json database backups create postgres-demo --name every10minutes --schedule "*/10 * * * *"
Database backup (every10minutes) for database postgr-b697-c429d7 has been created
```

### List backup

```bash
Scheduled backup
+-------------+---------------+------------+--------------+----------------+------------------+
| Database ID | Database Name | Software | Schedule | Backup Name | Backup |
+-------------+---------------+------------+--------------+----------------+------------------+
| 65dd81 | postgres-demo | PostgreSQL | */10 * * * * | every10minutes | 20240131-100009F |
+-------------+---------------+------------+--------------+----------------+------------------+
```

### Create Manual Backup

```bash
❯ ./civo --config staging.civo.json database backups create postgres-demo
```

### List

```bash
❯ ./civo --config staging.civo.json database backups ls postgres-demo
Scheduled backup
+-------------+---------------+------------+--------------+----------------+------------------+
| Database ID | Database Name | Software | Schedule | Backup Name | Backup |
+-------------+---------------+------------+--------------+----------------+------------------+
| 65dd81 | postgres-demo | PostgreSQL | */10 * * * * | every10minutes | 20240131-100009F |
+-------------+---------------+------------+--------------+----------------+------------------+
Manual backups
+-------------+---------------+------------+------------------+
| Database ID | Database Name | Software | Backup |
+-------------+---------------+------------+------------------+
| 65dd81 | postgres-demo | PostgreSQL | 20240131-095615F |
+-------------+---------------+------------+------------------+
```

### Restore from scheduled

```bash
❯ ./civo --config staging.civo.json database restore postgres-demo --name restorefromscheduledbackup --backup 20240131-102006F
Warning: Are you sure you want to restore db postgres-demo from 20240131-102006F backup (y/N) ? y
Restoring database postgres-demo from from backup 20240131-102006F
```

### Restore from manual

```bash
❯ ./civo --config staging.civo.json database restore postgres-demo --name restorefromscheduledbackup --backup 20240131-095615F
Warning: Are you sure you want to restore db postgres-demo from 20240131-095615F backup (y/N) ? y
Restoring database postgres-demo from from backup 20240131-095615F
```

## MySQL Backup

### Create

```bash
❯ ./civo --config staging.civo.json database backups create mysql-demo --name firstbackup --type manual
Database backup (firstbackup) for database mysql-demo has been created
```

### List backup

```bash
❯ ./civo --config staging.civo.json database backups ls mysql-demo
Manual backups
+-------------+---------------+-----------+-------------+----------+--------+
| Database ID | Database Name | Backup ID | Backup Name | Software | Status |
+-------------+---------------+-----------+-------------+----------+--------+
| 0d328d | mysql-demo | ba0466 | firstbackup | MySQL | READY |
+-------------+---------------+-----------+-------------+----------+--------+
```

### Restore

```bash
❯ ./civo --config staging.civo.json database restore mysql-demo --name restorefirstbackup --backup firstbackup
Warning: Are you sure you want to restore db mysql-demo from firstbackup backup (y/N) ? y
Restoring database mysql-demo from from backup firstbackup
```

0 comments on commit 917217d

Please sign in to comment.