Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tabacco
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai3
tools
tabacco
Commits
3654e8d1
Commit
3654e8d1
authored
Oct 20, 2019
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to optionally set cache dirs for restic
Cache directories are sharded by source name, enabling re-use.
parent
d19fa308
Pipeline
#4679
failed with stages
in 6 minutes and 1 second
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
6 deletions
+24
-6
repository_restic.go
repository_restic.go
+22
-2
types.go
types.go
+2
-4
No files found.
repository_restic.go
View file @
3654e8d1
...
...
@@ -26,6 +26,7 @@ type resticRepository struct {
excludes
[]
string
excludeFiles
[]
string
autoPrune
bool
cacheDirPath
string
initialized
sync
.
Once
}
...
...
@@ -96,6 +97,11 @@ func newResticRepository(params map[string]interface{}) (Repository, error) {
autoPrune
=
b
}
var
cacheDir
string
if
s
,
ok
:=
params
[
"cache_dir"
]
.
(
string
);
ok
{
cacheDir
=
s
}
tmpf
,
err
:=
ioutil
.
TempFile
(
""
,
"restic-pw-"
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -116,6 +122,7 @@ func newResticRepository(params map[string]interface{}) (Repository, error) {
excludes
:
ex
,
excludeFiles
:
exf
,
autoPrune
:
autoPrune
,
cacheDirPath
:
cacheDir
,
},
nil
}
...
...
@@ -152,10 +159,22 @@ func resticBackupTags(backup *Backup, ds *Dataset) string {
return
fmt
.
Sprintf
(
"--tag dataset_id=%s --tag backup_id=%s"
,
ds
.
ID
,
backup
.
ID
)
}
func
(
r
*
resticRepository
)
cacheArgs
(
ds
*
Dataset
)
string
{
if
r
.
cacheDirPath
==
""
{
return
"--no-cache"
}
dir
:=
filepath
.
Join
(
r
.
cacheDirPath
,
strings
.
Replace
(
ds
.
Source
,
"/"
,
"_"
,
-
1
))
if
_
,
err
:=
os
.
Stat
(
dir
);
os
.
IsNotExist
(
err
)
{
os
.
MkdirAll
(
dir
,
0700
)
}
return
fmt
.
Sprintf
(
"--cache-dir %s"
,
dir
)
}
func
(
r
*
resticRepository
)
BackupCmd
(
backup
*
Backup
,
ds
*
Dataset
,
inputFile
string
)
string
{
return
fmt
.
Sprintf
(
"%s backup
--no-cache
--exclude-caches --one-file-system %s --files-from %s"
,
"%s backup
%s
--exclude-caches --one-file-system %s --files-from %s"
,
r
.
resticCmd
(),
r
.
cacheArgs
(
ds
),
resticBackupTags
(
backup
,
ds
),
inputFile
,
)
...
...
@@ -210,8 +229,9 @@ func (r *resticRepository) BackupStreamCmd(backup *Backup, ds *Dataset) string {
fakePath
:=
datasetStdinPath
(
ds
)
return
fmt
.
Sprintf
(
// The --force prevents restic from trying to find a previous snapshot.
"%s backup
--no-cache
%s --force --stdin --stdin-filename %s"
,
"%s backup
%s
%s --force --stdin --stdin-filename %s"
,
r
.
resticCmd
(),
r
.
cacheArgs
(
ds
),
resticBackupTags
(
backup
,
ds
),
fakePath
,
)
...
...
types.go
View file @
3654e8d1
...
...
@@ -42,7 +42,7 @@ func (p Params) GetBool(key string) (bool, bool) {
// operation. Backups are initiated autonomously by individual hosts,
// so each Backup belongs to a single Host.
type
Backup
struct
{
//
Backup ID (globally unique identifier)
.
//
Unique identifier
.
ID
string
`json:"id"`
// Timestamp (backup start).
...
...
@@ -75,9 +75,7 @@ type Atom struct {
// databases (the atom we're interested in), which we might want to
// restore independently.
type
Dataset
struct
{
// Name of the dataset (path-like). Will be prepended to atom
// paths.
//Name string `json:"name"`
// Unique identifier.
ID
string
`json:"id"`
// Source is the name of the source that created this Dataset,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment