added inplace option for rsync

This commit is contained in:
Axel Kittenberger 2015-10-14 14:39:14 +02:00
parent a18ba20365
commit 5f74865f68
1 changed files with 70 additions and 33 deletions

View File

@ -16,17 +16,20 @@
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if not default then if not default
then
error( 'default not loaded' ) error( 'default not loaded' )
end end
if default.rsync then if default.rsync
then
error( 'default-rsync already loaded' ) error( 'default-rsync already loaded' )
end end
local rsync = { } local rsync = { }
default.rsync = rsync default.rsync = rsync
-- uses default collect -- uses default collect
@ -62,6 +65,7 @@ rsync.checkgauge = {
group = true, group = true,
hard_links = true, hard_links = true,
ignore_times = true, ignore_times = true,
inplace = true,
ipv4 = true, ipv4 = true,
ipv6 = true, ipv6 = true,
keep_dirlinks = true, keep_dirlinks = true,
@ -293,30 +297,34 @@ end
-- --
-- Prepares and checks a syncs configuration on startup. -- Prepares and checks a syncs configuration on startup.
-- --
rsync.prepare = function( rsync.prepare =
config, -- the configuration function(
level, -- additional error level for inherited use ( by rsyncssh ) config, -- the configuration
skipTarget -- used by rsyncssh, do not check for target level, -- additional error level for inherited use ( by rsyncssh )
) skipTarget -- used by rsyncssh, do not check for target
)
-- First let default.prepare test the checkgauge -- First let default.prepare test the checkgauge
default.prepare( config, level + 6 ) default.prepare( config, level + 6 )
if not skipTarget and not config.target then if not skipTarget and not config.target
then
error( error(
'default.rsync needs "target" configured', 'default.rsync needs "target" configured',
level level
) )
end end
if config.rsyncOps then if config.rsyncOps
then
error( error(
'"rsyncOps" is outdated please use the new rsync = { ... } syntax.', '"rsyncOps" is outdated please use the new rsync = { ... } syntax.',
level level
) )
end end
if config.rsyncOpts and config.rsync._extra then if config.rsyncOpts and config.rsync._extra
then
error( error(
'"rsyncOpts" is outdated in favor of the new rsync = { ... } syntax\n"' + '"rsyncOpts" is outdated in favor of the new rsync = { ... } syntax\n"' +
'for which you provided the _extra attribute as well.\n"' + 'for which you provided the _extra attribute as well.\n"' +
@ -325,7 +333,8 @@ rsync.prepare = function(
) )
end end
if config.rsyncOpts then if config.rsyncOpts
then
log( log(
'Warn', 'Warn',
'"rsyncOpts" is outdated. Please use the new rsync = { ... } syntax."' '"rsyncOpts" is outdated. Please use the new rsync = { ... } syntax."'
@ -335,7 +344,8 @@ rsync.prepare = function(
config.rsyncOpts = nil config.rsyncOpts = nil
end end
if config.rsyncBinary and config.rsync.binary then if config.rsyncBinary and config.rsync.binary
then
error( error(
'"rsyncBinary is outdated in favor of the new rsync = { ... } syntax\n"'+ '"rsyncBinary is outdated in favor of the new rsync = { ... } syntax\n"'+
'for which you provided the binary attribute as well.\n"' + 'for which you provided the binary attribute as well.\n"' +
@ -344,7 +354,8 @@ rsync.prepare = function(
) )
end end
if config.rsyncBinary then if config.rsyncBinary
then
log( log(
'Warn', 'Warn',
'"rsyncBinary" is outdated. Please use the new rsync = { ... } syntax."' '"rsyncBinary" is outdated. Please use the new rsync = { ... } syntax."'
@ -355,7 +366,8 @@ rsync.prepare = function(
end end
-- checks if the _computed argument exists already -- checks if the _computed argument exists already
if config.rsync._computed then if config.rsync._computed
then
error( error(
'please do not use the internal rsync._computed parameter', 'please do not use the internal rsync._computed parameter',
level level
@ -381,9 +393,12 @@ rsync.prepare = function(
} }
-- if archive is given the implications are filled in -- if archive is given the implications are filled in
if crsync.archive then if crsync.archive
for k, v in pairs( archiveFlags ) do then
if crsync[ k ] == nil then for k, v in pairs( archiveFlags )
do
if crsync[ k ] == nil
then
crsync[ k ] = v crsync[ k ] = v
end end
end end
@ -426,73 +441,94 @@ rsync.prepare = function(
local shorts = { '-' } local shorts = { '-' }
local shortsN = 2 local shortsN = 2
if crsync._extra then if crsync._extra
for k, v in ipairs( crsync._extra ) do then
for k, v in ipairs( crsync._extra )
do
computed[ computedN ] = v computed[ computedN ] = v
computedN = computedN + 1 computedN = computedN + 1
end end
end end
for k, flag in pairs( shortFlags ) do for k, flag in pairs( shortFlags )
if crsync[ k ] then do
if crsync[ k ]
then
shorts[ shortsN ] = flag shorts[ shortsN ] = flag
shortsN = shortsN + 1 shortsN = shortsN + 1
end end
end end
if crsync.devices and crsync.specials then if crsync.devices and crsync.specials
then
shorts[ shortsN ] = 'D' shorts[ shortsN ] = 'D'
shortsN = shortsN + 1 shortsN = shortsN + 1
else else
if crsync.devices then if crsync.devices
then
computed[ computedN ] = '--devices' computed[ computedN ] = '--devices'
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.specials then if crsync.specials
then
computed[ computedN ] = '--specials' computed[ computedN ] = '--specials'
computedN = computedN + 1 computedN = computedN + 1
end end
end end
if crsync.bwlimit then if crsync.bwlimit
then
computed[ computedN ] = '--bwlimit=' .. crsync.bwlimit computed[ computedN ] = '--bwlimit=' .. crsync.bwlimit
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.password_file then if crsync.inplace
then
computed[ computedN ] = '--inplace'
computedN = computedN + 1
end
if crsync.password_file
then
computed[ computedN ] = '--password-file=' .. crsync.password_file computed[ computedN ] = '--password-file=' .. crsync.password_file
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.rsh then if crsync.rsh
then
computed[ computedN ] = '--rsh=' .. crsync.rsh computed[ computedN ] = '--rsh=' .. crsync.rsh
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.rsync_path then if crsync.rsync_path
then
computed[ computedN ] = '--rsync-path=' .. crsync.rsync_path computed[ computedN ] = '--rsync-path=' .. crsync.rsync_path
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.temp_dir then if crsync.temp_dir
then
computed[ computedN ] = '--temp-dir=' .. crsync.temp_dir computed[ computedN ] = '--temp-dir=' .. crsync.temp_dir
computedN = computedN + 1 computedN = computedN + 1
end end
if crsync.timeout then if crsync.timeout
then
computed[ computedN ] = '--timeout=' .. crsync.timeout computed[ computedN ] = '--timeout=' .. crsync.timeout
computedN = computedN + 1 computedN = computedN + 1
end end
if shortsN ~= 2 then if shortsN ~= 2
then
computed[ 1 ] = table.concat( shorts, '' ) computed[ 1 ] = table.concat( shorts, '' )
else else
computed[ 1 ] = { } computed[ 1 ] = { }
end end
-- appends a / to target if not present -- appends a / to target if not present
if not skipTarget and string.sub(config.target, -1) ~= '/' then if not skipTarget and string.sub(config.target, -1) ~= '/'
then
config.target = config.target..'/' config.target = config.target..'/'
end end
@ -512,7 +548,8 @@ rsync.exitcodes = default.rsyncExitCodes
-- --
-- Calls rsync with this default options -- Calls rsync with this default options
-- --
rsync.rsync = { rsync.rsync =
{
-- The rsync binary to be called. -- The rsync binary to be called.
binary = '/usr/bin/rsync', binary = '/usr/bin/rsync',
links = true, links = true,