mirror of
https://github.com/tuna/tunasync.git
synced 2025-06-15 14:12:47 +00:00
[mirror config] extra rsync options (#107)
* support "rsync_options" array in config * add test for new options * fix tests
This commit is contained in:
parent
36010dc33e
commit
22cfdfc9c2
@ -45,6 +45,7 @@ docker_image = "tunathu/tunasync-scripts:latest"
|
|||||||
name = "gnu"
|
name = "gnu"
|
||||||
provider = "rsync"
|
provider = "rsync"
|
||||||
upstream = "rsync://mirrors.ocf.berkeley.edu/gnu/"
|
upstream = "rsync://mirrors.ocf.berkeley.edu/gnu/"
|
||||||
|
rsync_options = [ "--delete-excluded" ]
|
||||||
memory_limit = "256M"
|
memory_limit = "256M"
|
||||||
|
|
||||||
[[mirrors]]
|
[[mirrors]]
|
||||||
@ -72,6 +73,7 @@ name = "ubuntu"
|
|||||||
provider = "two-stage-rsync"
|
provider = "two-stage-rsync"
|
||||||
stage1_profile = "debian"
|
stage1_profile = "debian"
|
||||||
upstream = "rsync://archive.ubuntu.com/ubuntu/"
|
upstream = "rsync://archive.ubuntu.com/ubuntu/"
|
||||||
|
rsync_options = [ "--delete-excluded" ]
|
||||||
memory_limit = "256M"
|
memory_limit = "256M"
|
||||||
|
|
||||||
# vim: ft=toml
|
# vim: ft=toml
|
@ -135,6 +135,7 @@ type mirrorConfig struct {
|
|||||||
ExcludeFile string `toml:"exclude_file"`
|
ExcludeFile string `toml:"exclude_file"`
|
||||||
Username string `toml:"username"`
|
Username string `toml:"username"`
|
||||||
Password string `toml:"password"`
|
Password string `toml:"password"`
|
||||||
|
RsyncOptions []string `toml:"rsync_options"`
|
||||||
Stage1Profile string `toml:"stage1_profile"`
|
Stage1Profile string `toml:"stage1_profile"`
|
||||||
|
|
||||||
MemoryLimit string `toml:"memory_limit"`
|
MemoryLimit string `toml:"memory_limit"`
|
||||||
|
@ -132,6 +132,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
username: mirror.Username,
|
username: mirror.Username,
|
||||||
password: mirror.Password,
|
password: mirror.Password,
|
||||||
excludeFile: mirror.ExcludeFile,
|
excludeFile: mirror.ExcludeFile,
|
||||||
|
extraOptions: mirror.RsyncOptions,
|
||||||
workingDir: mirrorDir,
|
workingDir: mirrorDir,
|
||||||
logDir: logDir,
|
logDir: logDir,
|
||||||
logFile: filepath.Join(logDir, "latest.log"),
|
logFile: filepath.Join(logDir, "latest.log"),
|
||||||
@ -155,6 +156,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
username: mirror.Username,
|
username: mirror.Username,
|
||||||
password: mirror.Password,
|
password: mirror.Password,
|
||||||
excludeFile: mirror.ExcludeFile,
|
excludeFile: mirror.ExcludeFile,
|
||||||
|
extraOptions: mirror.RsyncOptions,
|
||||||
workingDir: mirrorDir,
|
workingDir: mirrorDir,
|
||||||
logDir: logDir,
|
logDir: logDir,
|
||||||
logFile: filepath.Join(logDir, "latest.log"),
|
logFile: filepath.Join(logDir, "latest.log"),
|
||||||
|
@ -122,9 +122,10 @@ func TestRsyncProviderWithAuthentication(t *testing.T) {
|
|||||||
username: "tunasync",
|
username: "tunasync",
|
||||||
password: "tunasyncpassword",
|
password: "tunasyncpassword",
|
||||||
workingDir: tmpDir,
|
workingDir: tmpDir,
|
||||||
|
extraOptions: []string{"--delete-excluded"},
|
||||||
logDir: tmpDir,
|
logDir: tmpDir,
|
||||||
logFile: tmpFile,
|
logFile: tmpFile,
|
||||||
useIPv6: true,
|
useIPv4: true,
|
||||||
interval: 600 * time.Second,
|
interval: 600 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +158,7 @@ exit 0
|
|||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"%s %s -aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
|
"%s %s -aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
|
||||||
"--delete --delete-after --delay-updates --safe-links "+
|
"--delete --delete-after --delay-updates --safe-links "+
|
||||||
"--timeout=120 --contimeout=120 -6 %s %s",
|
"--timeout=120 --contimeout=120 -4 --delete-excluded %s %s",
|
||||||
provider.username, provider.password, provider.upstreamURL, provider.WorkingDir(),
|
provider.username, provider.password, provider.upstreamURL, provider.WorkingDir(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -319,6 +320,7 @@ func TestTwoStageRsyncProvider(t *testing.T) {
|
|||||||
logFile: tmpFile,
|
logFile: tmpFile,
|
||||||
useIPv6: true,
|
useIPv6: true,
|
||||||
excludeFile: tmpFile,
|
excludeFile: tmpFile,
|
||||||
|
extraOptions: []string{"--delete-excluded", "--cache"},
|
||||||
username: "hello",
|
username: "hello",
|
||||||
password: "world",
|
password: "world",
|
||||||
}
|
}
|
||||||
@ -359,14 +361,14 @@ exit 0
|
|||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
|
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
|
||||||
"--timeout=120 --contimeout=120 --exclude dists/ -6 "+
|
"--timeout=120 --contimeout=120 --exclude dists/ -6 "+
|
||||||
"--exclude-from %s %s %s",
|
"--exclude-from %s --delete-excluded --cache %s %s",
|
||||||
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
||||||
),
|
),
|
||||||
targetDir,
|
targetDir,
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
|
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ "+
|
||||||
"--delete --delete-after --delay-updates --safe-links "+
|
"--delete --delete-after --delay-updates --safe-links "+
|
||||||
"--timeout=120 --contimeout=120 -6 --exclude-from %s %s %s",
|
"--timeout=120 --contimeout=120 -6 --exclude-from %s --delete-excluded --cache %s %s",
|
||||||
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -398,7 +400,7 @@ exit 0
|
|||||||
expectedOutput := fmt.Sprintf(
|
expectedOutput := fmt.Sprintf(
|
||||||
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
|
"-aHvh --no-o --no-g --stats --exclude .~tmp~/ --safe-links "+
|
||||||
"--timeout=120 --contimeout=120 --exclude dists/ -6 "+
|
"--timeout=120 --contimeout=120 --exclude dists/ -6 "+
|
||||||
"--exclude-from %s %s %s\n",
|
"--exclude-from %s --delete-excluded --cache %s %s\n",
|
||||||
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
provider.excludeFile, provider.upstreamURL, provider.WorkingDir(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ type rsyncConfig struct {
|
|||||||
name string
|
name string
|
||||||
rsyncCmd string
|
rsyncCmd string
|
||||||
upstreamURL, username, password, excludeFile string
|
upstreamURL, username, password, excludeFile string
|
||||||
|
extraOptions []string
|
||||||
workingDir, logDir, logFile string
|
workingDir, logDir, logFile string
|
||||||
useIPv6, useIPv4 bool
|
useIPv6, useIPv4 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
@ -65,6 +66,9 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
|
|||||||
if c.excludeFile != "" {
|
if c.excludeFile != "" {
|
||||||
options = append(options, "--exclude-from", c.excludeFile)
|
options = append(options, "--exclude-from", c.excludeFile)
|
||||||
}
|
}
|
||||||
|
if c.extraOptions != nil {
|
||||||
|
options = append(options, c.extraOptions...)
|
||||||
|
}
|
||||||
provider.options = options
|
provider.options = options
|
||||||
|
|
||||||
provider.ctx.Set(_WorkingDirKey, c.workingDir)
|
provider.ctx.Set(_WorkingDirKey, c.workingDir)
|
||||||
|
@ -15,6 +15,7 @@ type twoStageRsyncConfig struct {
|
|||||||
rsyncCmd string
|
rsyncCmd string
|
||||||
stage1Profile string
|
stage1Profile string
|
||||||
upstreamURL, username, password, excludeFile string
|
upstreamURL, username, password, excludeFile string
|
||||||
|
extraOptions []string
|
||||||
workingDir, logDir, logFile string
|
workingDir, logDir, logFile string
|
||||||
useIPv6 bool
|
useIPv6 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
@ -116,6 +117,9 @@ func (p *twoStageRsyncProvider) Options(stage int) ([]string, error) {
|
|||||||
if p.excludeFile != "" {
|
if p.excludeFile != "" {
|
||||||
options = append(options, "--exclude-from", p.excludeFile)
|
options = append(options, "--exclude-from", p.excludeFile)
|
||||||
}
|
}
|
||||||
|
if p.extraOptions != nil {
|
||||||
|
options = append(options, p.extraOptions...)
|
||||||
|
}
|
||||||
|
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user