mirror of
https://github.com/deajan/osync
synced 2024-11-11 07:10:40 +00:00
Added monitor mode
This commit is contained in:
parent
13420e6d83
commit
8a16a2233e
@ -4,6 +4,7 @@ SHORT FUTURE IMPROVEMENTS (post v1.0)
|
|||||||
- Sync and delete propagation function merge (master and slave functions are the same, reduces code size and maintain effort)
|
- Sync and delete propagation function merge (master and slave functions are the same, reduces code size and maintain effort)
|
||||||
- Tree function merge (current and after tree functions are the same except for output filename and logging, reduces code size and maintain effort)
|
- Tree function merge (current and after tree functions are the same except for output filename and logging, reduces code size and maintain effort)
|
||||||
- Tree functions execute piped commands (grep, awk) on master when launched on remote slave which can cause more bandwith usage
|
- Tree functions execute piped commands (grep, awk) on master when launched on remote slave which can cause more bandwith usage
|
||||||
|
- Daemonize osync --on-changes mode
|
||||||
|
|
||||||
FAR FUTURE IMPROVEMENTS
|
FAR FUTURE IMPROVEMENTS
|
||||||
-----------------------
|
-----------------------
|
||||||
@ -20,6 +21,7 @@ KNOWN ISSUES
|
|||||||
RECENT CHANGES
|
RECENT CHANGES
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
- Added monitor mode, which will launch a sync task upon file operations on master replica
|
||||||
- Changed conf file default format for ssh uri (old format is still compatible)
|
- Changed conf file default format for ssh uri (old format is still compatible)
|
||||||
- Added ssh uri support for slave replicas
|
- Added ssh uri support for slave replicas
|
||||||
- Improved execution hooks logs
|
- Improved execution hooks logs
|
||||||
|
@ -17,6 +17,7 @@ Bitpocked inspired me to write my own implementation of a two way sync script, i
|
|||||||
- Soft deletition and multiple backups handling
|
- Soft deletition and multiple backups handling
|
||||||
- Before / after command execution
|
- Before / after command execution
|
||||||
- Time control
|
- Time control
|
||||||
|
- Sync on changes
|
||||||
|
|
||||||
Osync uses a master / slave sync schema. It can sync local and local or local and remote directories. By definition, master replica should always be a local directory on the system osync runs on.
|
Osync uses a master / slave sync schema. It can sync local and local or local and remote directories. By definition, master replica should always be a local directory on the system osync runs on.
|
||||||
Also, osync uses pidlocks to prevent multiple concurrent sync processes on/to the same master / slave replica. Be sure a sync process is finished before launching next one.
|
Also, osync uses pidlocks to prevent multiple concurrent sync processes on/to the same master / slave replica. Be sure a sync process is finished before launching next one.
|
||||||
@ -72,6 +73,10 @@ Once you're confident about your fist runs, you may add osync as cron task with:
|
|||||||
|
|
||||||
$ ./osync.sh /path/to/your.conf --silent
|
$ ./osync.sh /path/to/your.conf --silent
|
||||||
|
|
||||||
|
Additionnaly, you may run osync in monitor mode, which means it will perform a sync upon file operations on master replica.
|
||||||
|
|
||||||
|
$ ./osync.sh /path/to/your.conf --on-changes
|
||||||
|
|
||||||
You may then find osync output in /var/log/osync-*.log (or current directory if /var/log is not writable).
|
You may then find osync output in /var/log/osync-*.log (or current directory if /var/log is not writable).
|
||||||
|
|
||||||
## Author
|
## Author
|
||||||
|
35
osync.sh
35
osync.sh
@ -1466,8 +1466,13 @@ function Init
|
|||||||
set -o pipefail
|
set -o pipefail
|
||||||
set -o errtrace
|
set -o errtrace
|
||||||
|
|
||||||
|
# Do not use exit and quit traps if osync runs in monitor mode
|
||||||
|
if [ $sync_on_changes -eq 0 ]
|
||||||
|
then
|
||||||
trap TrapStop SIGINT SIGKILL SIGHUP SIGTERM SIGQUIT
|
trap TrapStop SIGINT SIGKILL SIGHUP SIGTERM SIGQUIT
|
||||||
trap TrapQuit EXIT
|
trap TrapQuit EXIT
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$DEBUG" == "yes" ]
|
if [ "$DEBUG" == "yes" ]
|
||||||
then
|
then
|
||||||
trap 'TrapError ${LINENO} $?' ERR
|
trap 'TrapError ${LINENO} $?' ERR
|
||||||
@ -1667,6 +1672,7 @@ function Usage
|
|||||||
echo "--verbose: adds command outputs"
|
echo "--verbose: adds command outputs"
|
||||||
echo "--no-maxtime: disables any soft and hard execution time checks"
|
echo "--no-maxtime: disables any soft and hard execution time checks"
|
||||||
echo "--force-unlock: will override any existing active or dead locks on master and slave replica"
|
echo "--force-unlock: will override any existing active or dead locks on master and slave replica"
|
||||||
|
echo "--on-changes: will launch a sync as soon as there is some file activity on master replica."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Quick usage only:"
|
echo "Quick usage only:"
|
||||||
echo "--master= : Specify master replica path. Will contain state and backup directory."
|
echo "--master= : Specify master replica path. Will contain state and backup directory."
|
||||||
@ -1675,6 +1681,22 @@ function Usage
|
|||||||
exit 128
|
exit 128
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SyncOnChanges
|
||||||
|
{
|
||||||
|
if ! type -p inotifywait > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
LogError "No inotifywait command found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
inotifywait --exclude $OSYNC_DIR $RSYNC_EXCLUDE -qq -r -e create -e modify -e delete -e move -e attrib "$MASTER_SYNC_DIR/"
|
||||||
|
$osync_cmd "$ConfigFile"
|
||||||
|
done
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
# Comand line argument flags
|
# Comand line argument flags
|
||||||
dryrun=0
|
dryrun=0
|
||||||
silent=0
|
silent=0
|
||||||
@ -1691,6 +1713,8 @@ soft_alert_total=0
|
|||||||
error_alert=0
|
error_alert=0
|
||||||
soft_stop=0
|
soft_stop=0
|
||||||
quick_sync=0
|
quick_sync=0
|
||||||
|
sync_on_changes=0
|
||||||
|
osync_cmd=$0
|
||||||
|
|
||||||
if [ $# -eq 0 ]
|
if [ $# -eq 0 ]
|
||||||
then
|
then
|
||||||
@ -1731,6 +1755,9 @@ do
|
|||||||
--rsakey=*)
|
--rsakey=*)
|
||||||
SSH_RSA_PRIVATE_KEY=${i##*=}
|
SSH_RSA_PRIVATE_KEY=${i##*=}
|
||||||
;;
|
;;
|
||||||
|
--on-changes)
|
||||||
|
sync_on_changes=1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -1746,9 +1773,15 @@ then
|
|||||||
SOFT_DELETE_DAYS=30
|
SOFT_DELETE_DAYS=30
|
||||||
RESUME_TRY=1
|
RESUME_TRY=1
|
||||||
else
|
else
|
||||||
LoadConfigFile "$1"
|
ConfigFile="$1"
|
||||||
|
LoadConfigFile "$ConfigFile"
|
||||||
fi
|
fi
|
||||||
Init
|
Init
|
||||||
|
if [ $sync_on_changes -eq 1 ]
|
||||||
|
then
|
||||||
|
SyncOnChanges
|
||||||
|
exit
|
||||||
|
fi
|
||||||
DATE=$(date)
|
DATE=$(date)
|
||||||
Log "-------------------------------------------------------------"
|
Log "-------------------------------------------------------------"
|
||||||
Log "$DRY_WARNING $DATE - Osync v$OSYNC_VERSION script begin."
|
Log "$DRY_WARNING $DATE - Osync v$OSYNC_VERSION script begin."
|
||||||
|
Loading…
Reference in New Issue
Block a user