-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Backup & Restore #2053
Backup & Restore #2053
Conversation
This commit adds the backup command to the influxd binary as well as implements a SnapshotWriter in the influxdb package. By default the snapshot handler binds to 127.0.0.1 so it cannot be accessed outside of the local machine.
This commit adds the "influxd restore" command to the CLI. This allows a snapshot that has been produced by "influxd backup" to be restored to a config location and the broker and raft directories will be bootstrapped based on the state of the snapshot.
7044f7a
to
11c808f
Compare
…ckup-restore Conflicts: cmd/influxd/main.go cmd/influxd/run.go
} else if err != nil { | ||
return fmt.Errorf("next: entry=%s, err=%s", sf.Name, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it log output here just to let the user know that the file is being done? That way they get incremental output as the restore progresses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the unpack()
call should take a progress callback. I've seen this pattern other places, but can't remember where.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added progress: 4bc92c3
is it possible to specify the path for the snapshot so you can save it on another volume? |
@pauldix Yep, that's supported. Sorry that wasn't more clear in the PR description: $ influxd backup /path/to/my/snapshot |
|
||
backup downloads a snapshot of a data node and saves it to disk. | ||
|
||
-host <url> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: would this help output be more accurate if it read -host <host:port>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that it is used as part of a URL could be considered an implementation detail, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We parse it as a URL so it needs to specify scheme as well (http
or https
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the default shown should include the scheme, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 4bc92c3
|
||
// Ensure the backup returns an error if it cannot connect to the server. | ||
func TestBackupCommand_ErrConnectionRefused(t *testing.T) { | ||
// Start and immediate stop a server so we have a dead port. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nit-pick: "immediately".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed: 4bc92c3
Generally makes sense, happy to play with this once it's merged. +1 Did you consider compressing as well as tarring? a |
This commit adds incremental backup support. Snapshotting from the server now creates a full backup if one does not exist and creates numbered incremental backups after that. For example, if you ran: $ influxd backup /tmp/snapshot Then you'll see a full snapshot in /tmp/snapshot. If you run the same command again then an incremental snapshot will be created at /tmp/snapshot.0. Running it again will create /tmp/snapshot.1.
Overview
This pull request adds the ability to snapshot a single data node at a point-in-time and restore it.
Usage
While a data node is running, you can create a hot backup to a snapshot file (
mysnapshot
):By default, this can only be run from the data node itself. See configuration options below to snapshot from another machine.
Once you have your snapshot file, you can copy it to another machine and restore it:
This command will remove the broker and data directories listed in the configuration file provided and replace them with the data in the snapshot. Once the restore is complete, you can start the
influxd
server normally.Configuration Options
A configuration section has been added for the snapshot handler with the following defaults:
The bind address restricts snapshot so they can only be run from the local machine.
API
The following are the primary API additions:
Snapshots
Snapshot Reader
Snapshot Writer
Server Snapshot Writer Creation
Implementation
The snapshot file is a single
tar
archive that contains amanifest
file at the beginning, the data node'smeta
file next, and then a list of all shard files. The metastore and shards all use Bolt so they contain a point-in-time copy of the database when the backup was initiated.The broker node is not backed up because it can be materialized from the data in the data node. The restore command generates a broker meta store based on the highest index in the data node and generates a raft configuration based on the InfluxDB config passed in.
Caveats
This approach currently only works in clusters where the replication factor is the same as the number of nodes in the cluster. A cluster wide backup and restore will be done in the future.
TODO
Fixes: #1468 #1947