|
|
|
@ -4,7 +4,7 @@ PROGRAM="Osync" # Rsync based two way sync engine with fault tolerance
|
|
|
|
|
AUTHOR="(L) 2013-2015 by Orsiris \"Ozy\" de Jong"
|
|
|
|
|
CONTACT="http://www.netpower.fr/osync - ozy@netpower.fr"
|
|
|
|
|
PROGRAM_VERSION=1.00pre
|
|
|
|
|
PROGRAM_BUILD=2603201504
|
|
|
|
|
PROGRAM_BUILD=3003201502
|
|
|
|
|
|
|
|
|
|
## type doesn't work on platforms other than linux (bash). If if doesn't work, always assume output is not a zero exitcode
|
|
|
|
|
if ! type -p "$BASH" > /dev/null
|
|
|
|
@ -17,7 +17,7 @@ fi
|
|
|
|
|
if [ ! "$DEBUG" == "yes" ]
|
|
|
|
|
then
|
|
|
|
|
DEBUG=no
|
|
|
|
|
SLEEP_TIME=1
|
|
|
|
|
SLEEP_TIME=.1
|
|
|
|
|
else
|
|
|
|
|
SLEEP_TIME=3
|
|
|
|
|
fi
|
|
|
|
@ -59,8 +59,7 @@ ALERT_LOG_FILE=$RUN_DIR/osync_lastlog
|
|
|
|
|
|
|
|
|
|
function Dummy
|
|
|
|
|
{
|
|
|
|
|
sleep 1
|
|
|
|
|
exit 0
|
|
|
|
|
sleep .1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Log
|
|
|
|
@ -1504,16 +1503,17 @@ function SoftDelete
|
|
|
|
|
if [ $verbose -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
# Cannot launch log function from xargs, ugly hack
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Deleting file {}" > $RUN_DIR/osync_conflict_backup_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_$SCRIPT_PID)"
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Deleting directory {}" >> $RUN_DIR/osync_conflict_backup_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_$SCRIPT_PID)"
|
|
|
|
|
Dummy &
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Will delete file {}" > $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID)"
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Will delete directory {}" > $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $dryrun -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -rf "{}" > $RUN_DIR/osync_conflict_backup_$SCRIPT_PID &
|
|
|
|
|
$FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -rf "{}" > $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID &
|
|
|
|
|
else
|
|
|
|
|
Dummy &
|
|
|
|
|
fi
|
|
|
|
|
child_pid=$!
|
|
|
|
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
|
|
|
@ -1521,15 +1521,11 @@ function SoftDelete
|
|
|
|
|
if [ $retval -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Error while executing conflict backup cleanup on master replica."
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_master_$SCRIPT_PID)"
|
|
|
|
|
else
|
|
|
|
|
Log "Conflict backup cleanup complete on master replica."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $verbose -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_$SCRIPT_PID)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
elif [ -d "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR" ] && ! [ -w "$MASTER_SYNC_DIR$MASTER_BACKUP_DIR" ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Warning: Master replica conflict backup dir [$MASTER_SYNC_DIR$MASTER_BACKUP_DIR] isn't writable. Cannot clean old files."
|
|
|
|
@ -1539,13 +1535,26 @@ function SoftDelete
|
|
|
|
|
then
|
|
|
|
|
CheckConnectivity3rdPartyHosts
|
|
|
|
|
CheckConnectivityRemoteHost
|
|
|
|
|
|
|
|
|
|
if [ $dryrun -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
Log "Listing backups older than $CONFLICT_BACKUP_DAYS days on slave replica. Won't remove anything."
|
|
|
|
|
eval "$SSH_CMD \"if [ -w \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -ctime +$CONFLICT_BACKUP_DAYS; fi\"" &
|
|
|
|
|
else
|
|
|
|
|
Log "Removing backups older than $CONFLICT_BACKUP_DAYS days on remote slave replica."
|
|
|
|
|
eval "$SSH_CMD \"if [ -w \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -ctime +$CONFLICT_BACKUP_DAYS -exec rm -rf '{}' \;; fi\"" &
|
|
|
|
|
Log "Removing backups older than $CONFLICT_BACKUP_DAYS days on slave replica."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $verbose -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
# Cannot launch log function from xargs, ugly hack
|
|
|
|
|
eval "$SSH_CMD \"if [ -w \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo Will delete file {} && $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -type d -empty -ctime $CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo Will delete directory {}; fi\"" > $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID)"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $dryrun -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
eval "$SSH_CMD \"if [ -w \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR\\\" ]; then $COMMAND_SUDO $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -f \\\"{}\\\" && $REMOTE_FIND_CMD \\\"$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/\\\" -type d -empty -ctime $CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -rf \\\"{}\\\"; fi\"" > $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID &
|
|
|
|
|
else
|
|
|
|
|
Dummy &
|
|
|
|
|
fi
|
|
|
|
|
child_pid=$!
|
|
|
|
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
|
|
|
@ -1553,6 +1562,8 @@ function SoftDelete
|
|
|
|
|
if [ $retval -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Error while executing conflict backup cleanup on slave replica."
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID)"
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
Log "Conflict backup cleanup complete on slave replica."
|
|
|
|
|
fi
|
|
|
|
@ -1562,20 +1573,35 @@ function SoftDelete
|
|
|
|
|
if [ $dryrun -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
Log "Listing backups older than $CONFLICT_BACKUP_DAYS days on slave replica. Won't remove anything."
|
|
|
|
|
$FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -ctime +$CONFLICT_BACKUP_DAYS &
|
|
|
|
|
else
|
|
|
|
|
Log "Removing backups older than $CONFLICT_BACKUP_DAYS days on slave replica."
|
|
|
|
|
$FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -ctime +$CONFLICT_BACKUP_DAYS -exec rm -rf '{}' \; &
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $verbose -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
# Cannot launch log function from xargs, ugly hack
|
|
|
|
|
$FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Will delete file {}" > $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID)"
|
|
|
|
|
$FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} echo "Will delete directory {}" > $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID)"
|
|
|
|
|
Dummy &
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ $dryrun -ne 1 ]
|
|
|
|
|
then
|
|
|
|
|
$FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -type f -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -f "{}" && $FIND_CMD "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR/" -type d -empty -ctime +$CONFLICT_BACKUP_DAYS -print0 | xargs -0 -I {} rm -rf "{}" > $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID &
|
|
|
|
|
fi
|
|
|
|
|
child_pid=$!
|
|
|
|
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
|
|
|
|
retval=$?
|
|
|
|
|
if [ $retval -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Error while executing conflict backup cleanup on slave replica."
|
|
|
|
|
else
|
|
|
|
|
Log "Conflict backup cleanup complete on slave replica."
|
|
|
|
|
fi
|
|
|
|
|
WaitForCompletion $child_pid $SOFT_MAX_EXEC_TIME $HARD_MAX_EXEC_TIME
|
|
|
|
|
retval=$?
|
|
|
|
|
if [ $retval -ne 0 ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Error while executing conflict backup cleanup on slave replica."
|
|
|
|
|
Log "Command output:\n$(cat $RUN_DIR/osync_conflict_backup_slave_$SCRIPT_PID)"
|
|
|
|
|
else
|
|
|
|
|
Log "Conflict backup cleanup complete on slave replica."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
elif [ -d "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR" ] && ! [ -w "$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR" ]
|
|
|
|
|
then
|
|
|
|
|
LogError "Warning: Slave replica conflict backup dir [$SLAVE_SYNC_DIR$SLAVE_BACKUP_DIR] isn't writable. Cannot clean old files."
|
|
|
|
@ -2183,10 +2209,10 @@ then
|
|
|
|
|
GetLocalOS
|
|
|
|
|
InitLocalOSSettings
|
|
|
|
|
Init
|
|
|
|
|
SoftDelete
|
|
|
|
|
exit 0
|
|
|
|
|
GetRemoteOS
|
|
|
|
|
InitRemoteOSSettings
|
|
|
|
|
SoftDelete
|
|
|
|
|
exit $?
|
|
|
|
|
if [ $sync_on_changes -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
SyncOnChanges
|
|
|
|
|