Por sua pergunta de bônus, adicione a seguinte linha abaixo do comando rsync
no script de shell que forneci abaixo. Eu escrevi isso no comentário, mas vou adicioná-lo oficialmente à minha resposta aqui:
find /auto/std2/nat2/B -name '*.zip' -exec sh -c 'unzip -d 'dirname {}' {}' ';'
Isso manipulará a descompactação de todos os arquivos zip copiados via rsync
da pasta /auto/std2/nat2/A
para /auto/std2/nat2/B
Se você tem rsync
instalado, por que não apenas o cron dele e tem rsync
gerenciando o espelhamento de arquivos?
Criar script myrsyncscript.sh
Não se esqueça de torná-lo executável: chmod 700 myrsyncscript.sh
#!/bin/sh
LOCKFILE=/tmp/.hiddenrsync.lock
if [ -e $LOCKFILE ]
then
echo "Lockfile exists, process currently running."
echo "If no processes exist, remove $LOCKFILE to clear."
echo "Exiting..."
# mailx -s "Rsync Lock - Lock File found" [email protected] <<+
#Lockfile exists, process currently running.
#If no processes exist, remove $LOCKFILE to clear.
#+
exit
fi
touch $LOCKFILE
timestamp='date +%Y-%m-%d::%H:%M:%s'
echo "Process started at: $timestamp" >> $LOCKFILE
## Run Rsync if no Lockfile
rsync -a --no-compress /auto/std1/nat1/A /auto/std2/nat2/B
echo "Task Finished, removing lock file now at 'date +%Y-%m-%d::%H:%M:%s'"
rm $LOCKFILE
Discriminação de opções:
-a is for archive, which preserves ownership, permissions etc.
--no-compress as there's no lack of bandwidth between local devices
Opções adicionais que você pode considerar man rsync
:
--ignore-existing
skip updating files that exist on receiver
--update
This forces rsync to skip any files which exist on the destination and have a modified time that is newer than the source file. (If an existing destination file has a modification time equal to the source file’s, it will be updated if the sizes are different.) Note that this does not affect the copying of symlinks or other special files. Also, a difference of file format between the sender and receiver is always considered to be important enough for an update, no matter what date is on the objects. In other words, if the source has a directory where the destination has a file, the transfer would occur regardless of the timestamps.
This option is a transfer rule, not an exclude, so it doesn’t affect the data that goes into the file-lists, and thus it doesn’t affect deletions. It just limits the files that the receiver requests to be transferred.
Adicione-o ao cron e defina a frequência para o que lhe for mais conveniente:
Abra o cron com crontab -e
e adicione o abaixo:
### Every 5 minutes
*/5 * * * * /path/to/my/script/myrsyncscript.sh > /path/to/my/logfile 2>&1
# * * * * * command to execute
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)