The (modified) PERL script itself: ftpsync
A lot of changes were made to this script, for example using a file (.last) to indicate the last sync. Based on the mtime of this file it can determine which changes have taken place on both sides (PVR and server) and sync these changes.
#!/usr/bin/perl
#
# Usage: rename perlexpr [files]
#
# Example: rename 's/new$/old/' mah*.new
# Changes all the files prefixed with the text mah and suffixed with .new to be suffixed with .old instead
#
# Or: find /tmp -name '*~' -print | rename 's/^(.+)~$/.#$1/'
($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chomp(@ARGV);
}
foreach $_ (@ARGV) {
$old_name = $_;
# WARN if string already appeared
# Strip replacement from regexp, 0 will be operator, 1 source, 2 target and 3 options
@parts = split('/',$regexp);
# See if target appears in old name
if ($old_name =~ m/$parts[2]/i) {
die "ERROR: Target appears in original filename; cannot rename back!!! Stopping at $old_name\n";
}
$_ = $old_name;
# Run the regexp on $_ and generate new $_. Put error in $@
eval $regexp;
die $@ if $@;
$new_name = $_;
print "Renaming '$old_name' to '$new_name'\n" unless $old_name eq $new_name;
rename($old_name, $new_name) unless $old_name eq $new_name;
}
This PERL script is used by Bash scripts that do the renaming for me (this one changes
the ":" into "##"):
#!/bin/bash
# First all the files, otherwise if the dirs change the files cannot be found anymore!
find /KiSS/pvr/ -type f -print | rename 's/\:/##/g'
find /KiSS/pvr/ -type d -print | rename 's/\:/##/g'
replace_hash-colon
if [ "$?" -ne 0 ]; then
echo "ERROR: Renaming ## to : failed"
exit 1
fi
Note that it contains quite some error checking; I noticed that if the script is generating
errors and you continue syncing, you may loose all your recorded programs, and if the
script runs twice, you may loose it on both sides, happened to me quite a few times :-(
Note as well that I removed the redirecting of the stdouts to a log file, I assume you will be able to regenerate it.
The actual FTP script calling:
ftpsync -v -d -o 7200 -s 192.168.1.99 -r "/pvr/" -l "/KiSS/pvr/"
#ftpsync -k -v -d -o 7200 -s 192.168.1.99 -r "/pvr/" -l "/KiSS/pvr/"
Note the '-k' option being commented out: '-k' is for 'kidding', meaning that the
script does not actually perform the FTP operations (and .last updating); very useful
for debugging.
Also the '-o' option with 7200: The KiSS uses GMT internally and my Linux server is
now on GMT+2 hours (=7200 seconds)
Now the renaming of the 'strange' characters to more widely accepted characters for Windows access:
replace_colon-hash
if [ "$?" -ne 0 ]; then
echo "ERROR: Renaming : to ## failed"
exit 1
fi
Edwin