How can I create a job that copies the Directory /media/hdd/docs to the Windows share \192.168.1.3\Docs each night at 23:00, not overwriting existing files. The Windows share is shared to "Everyone" With read/Write on a Win2k12 server box
Assuming a few requirements in your scenario, I would use the rsync man page to find the appropriate options and write a shell script similar to the following untested script.
Create a new file called /opt/sync_docs.sh with the following contents.
#/bin/env sh # Use the second set of arguments for debugging OPTS="-avzn --ignore-existing" #OPTS="-avzn --ignore-existing -vv" rsync $OPTS /media/hdd/docs/ smb://smbserver/Docs/ >/var/log/rsync/sync_docs.log 2>&1 ERRMSG="Docs sync to windows shared failed, better check it out" if [ "$?" -ne "0" ]; then echo $ERRMSG; fi
Create the log directory and change ownership to the user you will run the script as. This user must have permission to write to the Samba share and permission to write to the log directory. From this point on, I'll refer to this user as "properuser".
# mkdir /var/log/rsync # chown properuser /var/log/rsync
Test the script with the log options uncommented. Once the script is tested, adjusted and working appropriately, I would want to schedule the script to be run by cron at 23:00 daily.
Create a cron job in the appropriate folder, usually inside /etc/cron.d/, and fill in your email address.
MAILTO="firstname.lastname@example.org" 0 23 * * * properuser /opt/sync_docs.sh
If you ever get an error message, just login and check the log file which will only show you the results of the last run.
# less /var/log/rsync/sync_docs.log