{"action":"created","comment":{"url":"https://api.github.com/repos/lxc/lxd/pulls/comments/188032334","pull_request_review_id":119922503,"id":188032334,"diff_hunk":"@@ -0,0 +1,297 @@\n+package main\n+\n+import (\n+\t\"archive/tar\"\n+\t\"bytes\"\n+\t\"io\"\n+\t\"os\"\n+\t\"path/filepath\"\n+\t\"time\"\n+\n+\tyaml \"gopkg.in/yaml.v2\"\n+\n+\t\"github.com/lxc/lxd/lxd/db\"\n+\t\"github.com/lxc/lxd/lxd/state\"\n+\t\"github.com/lxc/lxd/shared\"\n+\t\"github.com/lxc/lxd/shared/api\"\n+\t\"github.com/pkg/errors\"\n+)\n+\n+var ErrMissingIndexFile = errors.New(\"missing index.yaml\")\n+\n+// backup represents a container backup.\n+type backup struct {\n+\tstate     *state.State\n+\tcontainer container\n+\n+\t// Properties\n+\tid               int\n+\tname             string\n+\tcreationDate     time.Time\n+\texpiryDate       time.Time\n+\tcontainerOnly    bool\n+\toptimizedStorage bool\n+}\n+\n+type backupInfo struct {\n+\tName            string   `json:\"name\" yaml:\"name\"`\n+\tBackend         string   `json:\"backend\" yaml:\"backend\"`\n+\tPrivileged      bool     `json:\"privileged\" yaml:\"privileged\"`\n+\tPool            string   `json:\"pool\" yaml:\"pool\"`\n+\tSnapshots       []string `json:\"snapshots,omitempty\" yaml:\"snapshots,omitempty\"`\n+\tHasBinaryFormat bool     `json:\"-\" yaml:\"-\"`\n+}\n+\n+// Rename renames a container backup.\n+func (b *backup) Rename(newName string) error {\n+\tourStart, err := b.container.StorageStart()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tif ourStart {\n+\t\tdefer b.container.StorageStop()\n+\t}\n+\n+\t// Rename the database entry\n+\terr = b.state.Cluster.ContainerBackupRename(b.Name(), newName)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Rename the directories and files\n+\terr = b.container.Storage().ContainerBackupRename(*b, newName)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\treturn nil\n+}\n+\n+// Delete removes a container backup.\n+func (b *backup) Delete() error {\n+\tourStart, err := b.container.StorageStart()\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tif ourStart {\n+\t\tdefer b.container.StorageStop()\n+\t}\n+\n+\t// Remove the database record\n+\terr = b.state.Cluster.ContainerBackupRemove(b.Name())\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\t// Delete backup from storage\n+\terr = b.container.Storage().ContainerBackupDelete(b.Name())\n+\tif err != nil {\n+\t\treturn err\n+\t}","path":"lxd/backup.go","position":90,"original_position":90,"commit_id":"debdc7a645c88c2316b9a4d0e927a0ba9ddfe75f","original_commit_id":"debdc7a645c88c2316b9a4d0e927a0ba9ddfe75f","user":{"login":"brauner","id":7353573,"avatar_url":"https://avatars0.githubusercontent.com/u/7353573?v=4","gravatar_id":"","url":"https://api.github.com/users/brauner","html_url":"https://github.com/brauner","followers_url":"https://api.github.com/users/brauner/followers","following_url":"https://api.github.com/users/brauner/following{/other_user}","gists_url":"https://api.github.com/users/brauner/gists{/gist_id}","starred_url":"https://api.github.com/users/brauner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brauner/subscriptions","organizations_url":"https://api.github.com/users/brauner/orgs","repos_url":"https://api.github.com/users/brauner/repos","events_url":"https://api.github.com/users/brauner/events{/privacy}","received_events_url":"https://api.github.com/users/brauner/received_events","type":"User","site_admin":false},"body":"The other way around is better: first wipe the on-disk stuff then do the database delete. It doesn't make sense to have the on-disk stuff laying around but the db entry be gone. :)","created_at":"2018-05-14T17:20:26Z","updated_at":"2018-05-14T17:32:46Z","html_url":"https://github.com/lxc/lxd/pull/4463#discussion_r188032334","pull_request_url":"https://api.github.com/repos/lxc/lxd/pulls/4463","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/lxc/lxd/pulls/comments/188032334"},"html":{"href":"https://github.com/lxc/lxd/pull/4463#discussion_r188032334"},"pull_request":{"href":"https://api.github.com/repos/lxc/lxd/pulls/4463"}}},"pull_request":{"url":"https://api.github.com/repos/lxc/lxd/pulls/4463","id":181959346,"html_url":"https://github.com/lxc/lxd/pull/4463","diff_url":"https://github.com/lxc/lxd/pull/4463.diff","patch_url":"https://github.com/lxc/lxd/pull/4463.patch","issue_url":"https://api.github.com/repos/lxc/lxd/issues/4463","number":4463,"state":"open","locked":false,"title":"Container backups","user":{"login":"monstermunchkin","id":244787,"avatar_url":"https://avatars3.githubusercontent.com/u/244787?v=4","gravatar_id":"","url":"https://api.github.com/users/monstermunchkin","html_url":"https://github.com/monstermunchkin","followers_url":"https://api.github.com/users/monstermunchkin/followers","following_url":"https://api.github.com/users/monstermunchkin/following{/other_user}","gists_url":"https://api.github.com/users/monstermunchkin/gists{/gist_id}","starred_url":"https://api.github.com/users/monstermunchkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monstermunchkin/subscriptions","organizations_url":"https://api.github.com/users/monstermunchkin/orgs","repos_url":"https://api.github.com/users/monstermunchkin/repos","events_url":"https://api.github.com/users/monstermunchkin/events{/privacy}","received_events_url":"https://api.github.com/users/monstermunchkin/received_events","type":"User","site_admin":false},"body":"This feature allows importing and exporting containers (with snapshots).\r\n\r\n## Status\r\nWhat has been done so far:\r\n\r\n- [x] Database\r\n- [x] API endpoints\r\n  - [x] /1.0/containers/NAME/backups (GET)\r\n  - [x] /1.0/containers/NAME/backups (POST)\r\n  - [x] /1.0/containers/NAME/backups/NAME (DELETE)\r\n  - [x] /1.0/containers/NAME/backups/NAME (GET)\r\n  - [x] /1.0/containers/NAME/backups/NAME (POST)\r\n  - [x] /1.0/containers/NAME/backups/NAME/export (GET)\r\n  - [x] /1.0/containers (extend POST)\r\n- [x] Storage\r\n  - [x] dir\r\n  - [x] LVM\r\n  - [x] Btrfs\r\n  - [x] ZFS\r\n  - [x] Ceph\r\n- [x] Commands\r\n  - [x] `lxc export [<remote>:]<container> [target] [--container-only] [--optimized-storage]`\r\n  - [x] `lxc import [<remote>:] <backup file>`\r\n- [x] Documentation\r\n- [x] Tests","created_at":"2018-04-16T19:05:52Z","updated_at":"2018-05-14T17:32:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0a9d1044c7f3bbfeed9a374661be19a415eea658","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/lxc/lxd/pulls/4463/commits","review_comments_url":"https://api.github.com/repos/lxc/lxd/pulls/4463/comments","review_comment_url":"https://api.github.com/repos/lxc/lxd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lxc/lxd/issues/4463/comments","statuses_url":"https://api.github.com/repos/lxc/lxd/statuses/debdc7a645c88c2316b9a4d0e927a0ba9ddfe75f","head":{"label":"monstermunchkin:issues/3730","ref":"issues/3730","sha":"debdc7a645c88c2316b9a4d0e927a0ba9ddfe75f","user":{"login":"monstermunchkin","id":244787,"avatar_url":"https://avatars3.githubusercontent.com/u/244787?v=4","gravatar_id":"","url":"https://api.github.com/users/monstermunchkin","html_url":"https://github.com/monstermunchkin","followers_url":"https://api.github.com/users/monstermunchkin/followers","following_url":"https://api.github.com/users/monstermunchkin/following{/other_user}","gists_url":"https://api.github.com/users/monstermunchkin/gists{/gist_id}","starred_url":"https://api.github.com/users/monstermunchkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monstermunchkin/subscriptions","organizations_url":"https://api.github.com/users/monstermunchkin/orgs","repos_url":"https://api.github.com/users/monstermunchkin/repos","events_url":"https://api.github.com/users/monstermunchkin/events{/privacy}","received_events_url":"https://api.github.com/users/monstermunchkin/received_events","type":"User","site_admin":false},"repo":{"id":78421883,"name":"lxd","full_name":"monstermunchkin/lxd","owner":{"login":"monstermunchkin","id":244787,"avatar_url":"https://avatars3.githubusercontent.com/u/244787?v=4","gravatar_id":"","url":"https://api.github.com/users/monstermunchkin","html_url":"https://github.com/monstermunchkin","followers_url":"https://api.github.com/users/monstermunchkin/followers","following_url":"https://api.github.com/users/monstermunchkin/following{/other_user}","gists_url":"https://api.github.com/users/monstermunchkin/gists{/gist_id}","starred_url":"https://api.github.com/users/monstermunchkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monstermunchkin/subscriptions","organizations_url":"https://api.github.com/users/monstermunchkin/orgs","repos_url":"https://api.github.com/users/monstermunchkin/repos","events_url":"https://api.github.com/users/monstermunchkin/events{/privacy}","received_events_url":"https://api.github.com/users/monstermunchkin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/monstermunchkin/lxd","description":"Daemon based on liblxc offering a REST API to manage containers","fork":true,"url":"https://api.github.com/repos/monstermunchkin/lxd","forks_url":"https://api.github.com/repos/monstermunchkin/lxd/forks","keys_url":"https://api.github.com/repos/monstermunchkin/lxd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monstermunchkin/lxd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monstermunchkin/lxd/teams","hooks_url":"https://api.github.com/repos/monstermunchkin/lxd/hooks","issue_events_url":"https://api.github.com/repos/monstermunchkin/lxd/issues/events{/number}","events_url":"https://api.github.com/repos/monstermunchkin/lxd/events","assignees_url":"https://api.github.com/repos/monstermunchkin/lxd/assignees{/user}","branches_url":"https://api.github.com/repos/monstermunchkin/lxd/branches{/branch}","tags_url":"https://api.github.com/repos/monstermunchkin/lxd/tags","blobs_url":"https://api.github.com/repos/monstermunchkin/lxd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monstermunchkin/lxd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monstermunchkin/lxd/git/refs{/sha}","trees_url":"https://api.github.com/repos/monstermunchkin/lxd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monstermunchkin/lxd/statuses/{sha}","languages_url":"https://api.github.com/repos/monstermunchkin/lxd/languages","stargazers_url":"https://api.github.com/repos/monstermunchkin/lxd/stargazers","contributors_url":"https://api.github.com/repos/monstermunchkin/lxd/contributors","subscribers_url":"https://api.github.com/repos/monstermunchkin/lxd/subscribers","subscription_url":"https://api.github.com/repos/monstermunchkin/lxd/subscription","commits_url":"https://api.github.com/repos/monstermunchkin/lxd/commits{/sha}","git_commits_url":"https://api.github.com/repos/monstermunchkin/lxd/git/commits{/sha}","comments_url":"https://api.github.com/repos/monstermunchkin/lxd/comments{/number}","issue_comment_url":"https://api.github.com/repos/monstermunchkin/lxd/issues/comments{/number}","contents_url":"https://api.github.com/repos/monstermunchkin/lxd/contents/{+path}","compare_url":"https://api.github.com/repos/monstermunchkin/lxd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monstermunchkin/lxd/merges","archive_url":"https://api.github.com/repos/monstermunchkin/lxd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monstermunchkin/lxd/downloads","issues_url":"https://api.github.com/repos/monstermunchkin/lxd/issues{/number}","pulls_url":"https://api.github.com/repos/monstermunchkin/lxd/pulls{/number}","milestones_url":"https://api.github.com/repos/monstermunchkin/lxd/milestones{/number}","notifications_url":"https://api.github.com/repos/monstermunchkin/lxd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monstermunchkin/lxd/labels{/name}","releases_url":"https://api.github.com/repos/monstermunchkin/lxd/releases{/id}","deployments_url":"https://api.github.com/repos/monstermunchkin/lxd/deployments","created_at":"2017-01-09T11:14:56Z","updated_at":"2017-01-09T11:14:59Z","pushed_at":"2018-05-14T16:58:18Z","git_url":"git://github.com/monstermunchkin/lxd.git","ssh_url":"git@github.com:monstermunchkin/lxd.git","clone_url":"https://github.com/monstermunchkin/lxd.git","svn_url":"https://github.com/monstermunchkin/lxd","homepage":"https://linuxcontainers.org/lxd","size":18247,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"lxc:master","ref":"master","sha":"1a13add2fbb31449737093c6133be1f026d89aa7","user":{"login":"lxc","id":2301756,"avatar_url":"https://avatars2.githubusercontent.com/u/2301756?v=4","gravatar_id":"","url":"https://api.github.com/users/lxc","html_url":"https://github.com/lxc","followers_url":"https://api.github.com/users/lxc/followers","following_url":"https://api.github.com/users/lxc/following{/other_user}","gists_url":"https://api.github.com/users/lxc/gists{/gist_id}","starred_url":"https://api.github.com/users/lxc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lxc/subscriptions","organizations_url":"https://api.github.com/users/lxc/orgs","repos_url":"https://api.github.com/users/lxc/repos","events_url":"https://api.github.com/users/lxc/events{/privacy}","received_events_url":"https://api.github.com/users/lxc/received_events","type":"Organization","site_admin":false},"repo":{"id":26192117,"name":"lxd","full_name":"lxc/lxd","owner":{"login":"lxc","id":2301756,"avatar_url":"https://avatars2.githubusercontent.com/u/2301756?v=4","gravatar_id":"","url":"https://api.github.com/users/lxc","html_url":"https://github.com/lxc","followers_url":"https://api.github.com/users/lxc/followers","following_url":"https://api.github.com/users/lxc/following{/other_user}","gists_url":"https://api.github.com/users/lxc/gists{/gist_id}","starred_url":"https://api.github.com/users/lxc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lxc/subscriptions","organizations_url":"https://api.github.com/users/lxc/orgs","repos_url":"https://api.github.com/users/lxc/repos","events_url":"https://api.github.com/users/lxc/events{/privacy}","received_events_url":"https://api.github.com/users/lxc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lxc/lxd","description":"Daemon based on liblxc offering a REST API to manage containers","fork":false,"url":"https://api.github.com/repos/lxc/lxd","forks_url":"https://api.github.com/repos/lxc/lxd/forks","keys_url":"https://api.github.com/repos/lxc/lxd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lxc/lxd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lxc/lxd/teams","hooks_url":"https://api.github.com/repos/lxc/lxd/hooks","issue_events_url":"https://api.github.com/repos/lxc/lxd/issues/events{/number}","events_url":"https://api.github.com/repos/lxc/lxd/events","assignees_url":"https://api.github.com/repos/lxc/lxd/assignees{/user}","branches_url":"https://api.github.com/repos/lxc/lxd/branches{/branch}","tags_url":"https://api.github.com/repos/lxc/lxd/tags","blobs_url":"https://api.github.com/repos/lxc/lxd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lxc/lxd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lxc/lxd/git/refs{/sha}","trees_url":"https://api.github.com/repos/lxc/lxd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lxc/lxd/statuses/{sha}","languages_url":"https://api.github.com/repos/lxc/lxd/languages","stargazers_url":"https://api.github.com/repos/lxc/lxd/stargazers","contributors_url":"https://api.github.com/repos/lxc/lxd/contributors","subscribers_url":"https://api.github.com/repos/lxc/lxd/subscribers","subscription_url":"https://api.github.com/repos/lxc/lxd/subscription","commits_url":"https://api.github.com/repos/lxc/lxd/commits{/sha}","git_commits_url":"https://api.github.com/repos/lxc/lxd/git/commits{/sha}","comments_url":"https://api.github.com/repos/lxc/lxd/comments{/number}","issue_comment_url":"https://api.github.com/repos/lxc/lxd/issues/comments{/number}","contents_url":"https://api.github.com/repos/lxc/lxd/contents/{+path}","compare_url":"https://api.github.com/repos/lxc/lxd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lxc/lxd/merges","archive_url":"https://api.github.com/repos/lxc/lxd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lxc/lxd/downloads","issues_url":"https://api.github.com/repos/lxc/lxd/issues{/number}","pulls_url":"https://api.github.com/repos/lxc/lxd/pulls{/number}","milestones_url":"https://api.github.com/repos/lxc/lxd/milestones{/number}","notifications_url":"https://api.github.com/repos/lxc/lxd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lxc/lxd/labels{/name}","releases_url":"https://api.github.com/repos/lxc/lxd/releases{/id}","deployments_url":"https://api.github.com/repos/lxc/lxd/deployments","created_at":"2014-11-04T22:40:52Z","updated_at":"2018-05-13T16:35:02Z","pushed_at":"2018-05-14T17:06:24Z","git_url":"git://github.com/lxc/lxd.git","ssh_url":"git@github.com:lxc/lxd.git","clone_url":"https://github.com/lxc/lxd.git","svn_url":"https://github.com/lxc/lxd","homepage":"https://linuxcontainers.org/lxd","size":20120,"stargazers_count":1763,"watchers_count":1763,"language":"Go","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":430,"mirror_url":null,"archived":false,"open_issues_count":48,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":430,"open_issues":48,"watchers":1763,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lxc/lxd/pulls/4463"},"html":{"href":"https://github.com/lxc/lxd/pull/4463"},"issue":{"href":"https://api.github.com/repos/lxc/lxd/issues/4463"},"comments":{"href":"https://api.github.com/repos/lxc/lxd/issues/4463/comments"},"review_comments":{"href":"https://api.github.com/repos/lxc/lxd/pulls/4463/comments"},"review_comment":{"href":"https://api.github.com/repos/lxc/lxd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lxc/lxd/pulls/4463/commits"},"statuses":{"href":"https://api.github.com/repos/lxc/lxd/statuses/debdc7a645c88c2316b9a4d0e927a0ba9ddfe75f"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"brauner"}}