Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement backup/restore CLI subcommands #19864

Merged
merged 7 commits into from
Nov 5, 2020
Merged

Conversation

benbjohnson
Copy link
Contributor

@benbjohnson benbjohnson commented Oct 29, 2020

Overview

This pull request adds the influx backup and influx restore commands to the OSS 2.0 CLI. It combines the functionality of the 1.x commands of the same name but updates them to work with organizations & buckets.

Usage

Backup

# Backs up all data to the /mybackup directory.
$ influx backup /mybackup

# Backs up only data for organization "influx".
$ influx backup -o influx /mybackup

Restore

Full restore

A full restore completely deletes all data on the server and replaces it with the data in the backup. This includes all org/bucket meta data as well as other info like dashboards:

$ influx restore --full /mybackup

Partial restore

To restore only the bucket shard data, a partial restore can be done:

# Restores all data from the /mybackup directory to the local InfluxDB server.
$ influx restore /mybackup

# Restores only data for the "mybkt" bucket in the "influx" organization.
$ influx restore -o influx -b mybkt /mybackup

# Restores data from "mybkt" into a new bucket named "myotherbkt"
$ influx restore -o influx -b mybkt --new-bucket myotherbkt /mybackup

  • CHANGELOG.md updated with a link to the PR (not the Issue)
  • Well-formatted commit messages
  • Rebased/mergeable
  • Tests pass
  • http/swagger.yml updated (if modified Go structs or API)
  • Feature flagged (if modified API)
  • Documentation updated or issue created (provide link to issue/pr)
  • Signed CLA (if not already signed)

@benbjohnson benbjohnson self-assigned this Oct 29, 2020
@benbjohnson benbjohnson changed the title Implement backup/restore CLI subcommands feat: Implement backup/restore CLI subcommands Oct 29, 2020
Comment on lines 30 to 35
// TODO(bbj): Correct permissions.
if err := IsAllowedAll(ctx, influxdb.ReadAllPermissions()); err != nil {
return 0, nil, err
return err
}
return b.s.CreateBackup(ctx)
return b.s.BackupKVStore(ctx, w)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartcarnie I don't know the permissions we're using too well so I just left this as a TODO. Should this be OwnerPermissions()? Is there a better permission set for backup/restore?

Copy link
Contributor

@stuartcarnie stuartcarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really great, Ben! Thanks so much for pulling all this together.

I have experimented with the tool and the backups appear to be working after I added a minor tweak (see one of my comments). I could confirm the manifest, bolt and TSM files were in my backup path.

I was not able to restore the database, as the tool failed with the following errors.

Trying to restore into the existing bucket:

❯ bin/darwin/influx restore -b my-bucket ~/tmp/backup/
2020-10-30T23:33:01.195380Z	info	Resources opened	{"log_id": "0QAyZOLl000", "path": "/Users/stuartcarnie/tmp/backup/20201030T230351Z.bolt"}
2020-10-30T23:33:01.195762Z	info	Restoring organization	{"log_id": "0QAyZOLl000", "id": "93b0c30ea94cb097", "name": "my-org"}
2020-10-30T23:33:01.198169Z	info	Restoring bucket	{"log_id": "0QAyZOLl000", "id": "7425a44ac4116e88", "name": "my-bucket"}
Error: Cannot create bucket: bucket with name my-bucket already exists.
See 'influx restore -h' for help

Tried to restore into a new bucket:

❯ bin/darwin/influx restore -b foo ~/tmp/backup/
2020-10-30T23:33:10.379596Z	info	Resources opened	{"log_id": "0QAyZxDl000", "path": "/Users/stuartcarnie/tmp/backup/20201030T230351Z.bolt"}
2020-10-30T23:33:10.379950Z	info	Restoring organization	{"log_id": "0QAyZxDl000", "id": "93b0c30ea94cb097", "name": "my-org"}
Error: Bucket "foo" not found.
See 'influx restore -h' for help

cmd/influx/backup.go Show resolved Hide resolved
cmd/influx/backup.go Show resolved Hide resolved
http/backup_service.go Show resolved Hide resolved
@benbjohnson benbjohnson force-pushed the backup-restore branch 2 times, most recently from e55abd7 to fdf4eed Compare November 2, 2020 15:59
@benbjohnson
Copy link
Contributor Author

@stuartcarnie I added the ShardGroup.IsDeleted() check & returned ENotFound from BackupShard().

As for the restore usage, the -b flag is the filter for the bucket to restore and --new-bucket is the flag for the bucket to restore to. I agree the CLI flags are confusing but I tried to base it on the flags in the old 1.x version.

@stuartcarnie
Copy link
Contributor

As for the restore usage, the -b flag is the filter for the bucket to restore and --new-bucket is the flag for the bucket to restore to. I agree the CLI flags are confusing but I tried to base it on the flags in the old 1.x version.

Ahh right – I didn't even catch that. Sorry for the user error 🤦

I'll take another pass over it shortly

Copy link
Contributor

@sanderson sanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

backup.go Outdated Show resolved Hide resolved
backup.go Show resolved Hide resolved
@danxmoran danxmoran dismissed stuartcarnie’s stale review November 5, 2020 22:27

All requests were addressed, clearing to unblock merge

@benbjohnson benbjohnson merged commit a849bfd into master Nov 5, 2020
@benbjohnson benbjohnson deleted the backup-restore branch November 5, 2020 22:39
@stuartcarnie
Copy link
Contributor

Great work, @benbjohnson!

@stuartcarnie stuartcarnie added the area/2.x OSS 2.0 related issues and PRs label Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backup and restore area/2.x OSS 2.0 related issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants