How to create a shell script to create a folder by using the today's date to take backup using rsync command on every evening around 7 pm.
Kindly help.
Thanks.
To be more precise,
I want to create a script which matches the today's date with server's date format, if matches then creates the folder named date itself in the mentioned path "/tmp/test/files/testing/".
Moreover, after that it searches for the files which are created by today's date by using find command -newermt from some path, lets say "/var/www/path" and rsync command those files into /mnt/.
I'm kinda new shell scripter however, kindly help me with the script.
Thanks,
Bakula
We will help you.
But did you try something ?
If using rsync
, examine its options carefully.
Perhaps issuing a find
first using absolute path, print its output to file then processes it with rsync
--files-from=FILE read list of source-file names from FILE
Or just mkdir
and rsync
into it, without find
execution.
What do you think?
Regards
Peasant
This should get you pretty close.
F_LOC=/tmp/test/files/testing
S_LOC=/var/www/path
R_FILE=/tmp/reffile.$$
trap "rm -f \"${R_FILE}\"" EXIT HUP INT QUIT
today=$(date +%Y%m%d)
touch -t ${today}0000 "${R_FILE}"
[ -d "${F_LOC}/$today" ] || mkdir -p "${F_LOC}/$today"
cd "${F_LOC}"
(
cd "${S_LOC}"
find . -type f -newer "${R_FILE}" -print0
) | rsync -av0RD --files-from=- "${S_LOC}" "./$today"
You can remove v (verbose) from the rsync options above once you are happy it is working as intended.