I Have a backup tool, which copies Directory from host A and keeps in host B. This directory contains sub directories and files in it. After copying this directory and its sub directories and files time stamp is showing current date. Its not showing original time stamp in host A.

Everyday this tool copies directory from host A and keeps in host B. I have a script which copies time stamp from source directory and matches with destination directory. But this script only works locally.

# change timestamp accordingly to original directory of files
find . -printf '%P\n' |
while read fname
TS=$(stat -c '%Y' "${BASE_OLD}/${fname}")
TIMESTAMP=$(date -d @${TS})
touch -m -d "${TIMESTAMP}" "${BASE_NEW}/${fname}"
echo "${BASE_NEW}/${fname}"

I need a script to ssh to host A and match the time stamp with directory host B.


We're not a script writing service, I would imagine though that you could hack something up with ssh.

My suggestion would be to use a tool that copies the timestamps correctly and to that end I would suggest using rsync.

In particular the -t switch

-t, --times preserve modification times

note that the -a switch includes -t

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

so for example

rsync -avz /testing/etc user@example.com:/home/backup

should copy files from your local machine to the remote machine preserving the timestamps.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.