#!/bin/csh # rsynchro: a script to synchronize selected local files with # those on a remote host, and vice versa. # # Mark Alford, 2000 # you set these: set remote_dir = "username@distant.machine.edu:~/backups" set local_dir = ${HOME} set listfile_path = ${HOME}/rsynchro.lis # The listfile specifies which files in $local_dir will be # synchronized with $remote_dir (or vice versa). set connect_command = "ssh" if `grep -c ' $' ${listfile_path}` != 0 then echo WARNING: some lines in ${listfile_path} have trailing spaces endif echo Upload from ${HOST}:${local_dir} to ${remote_dir}, echo or echo Download from ${remote_dir} to ${HOST}:${local_dir} \? echo \(up/down\)\? set resp = $< if ${resp} == 'up' then set from_dir = $local_dir set from_dir_desc = ${HOST}:${local_dir} set to_dir = ${remote_dir} set to_dir_desc = ${remote_dir} else if ${resp} == 'down' then set to_dir = $local_dir set to_dir_desc = ${HOST}:${local_dir} set from_dir = ${remote_dir} set from_dir_desc = ${remote_dir} else exit endif endif set resp = xxx while ( $resp != 'y' && $resp != 'n' ) echo Delete files that exist on ${to_dir_desc} echo but do not exist on ${from_dir_desc} \(y/n\)\? set resp = $< end if ${resp} == 'y' then set delopt = "--delete" else set delopt = "" endif echo copying files listed in ${listfile_path} echo from ${from_dir_desc} echo \ \ to ${to_dir_desc} if ${delopt} == "--delete" then echo \*\*\*WITH DELETION\*\*\* endif echo set resp = xxx while ( $resp != 'y' && $resp != 'n' ) echo Do a trial run first \(no files will be modified\) \(y/n\)\? set resp = $< end if ${resp} == 'y' then rsync -e "${connect_command}" --compress --archive ${delopt} --update \ --verbose --progress --backup --suffix=~ --dry-run \ --include-from=${listfile_path} --exclude "*" \ ${from_dir}/ ${to_dir} set resp2 = xxx while ( $resp2 != 'y' && $resp2 != 'n' ) echo Now do it for real \(y/n\)\? set resp2 = $< end set do_it = $resp2 else set do_it = 'y' endif if ${do_it} == 'y' then rsync -e "${connect_command}" --compress --archive ${delopt} --update \ --verbose --progress --backup --suffix=~ \ --include-from=${listfile_path} --exclude "*" \ ${from_dir}/ ${to_dir} endif # Note that the '--backup --suffix=~' options increase safety: instead # of deleting files, rsync moves 'file' to 'file~'. # If you find this produces too much crap, remove those options. exit