1 |
joko |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
# --------------------------------------------------------- |
4 |
|
|
# "Rsync Here" v0.01 |
5 |
|
|
# --------------------------------------------------------- |
6 |
|
|
|
7 |
|
|
use strict; |
8 |
|
|
use warnings; |
9 |
|
|
|
10 |
|
|
# get / validate arguments |
11 |
|
|
my $sourcePath_arg = shift; |
12 |
|
|
if (!$sourcePath_arg) { |
13 |
|
|
print "no source path given, exit.", "\n"; |
14 |
|
|
exit; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
|
# config |
18 |
|
|
my $bash = "bash"; |
19 |
|
|
my $rsync = "rsync"; |
20 |
|
|
my $remote_ssh_prefix = 'joko@martha'; |
21 |
|
|
my $remote_target_base = '~/backup'; |
22 |
|
|
|
23 |
|
|
# main - convert source path |
24 |
|
|
my $sourcePath_win32 = $sourcePath_arg; |
25 |
|
|
my $sourcePath = $sourcePath_win32; |
26 |
|
|
$sourcePath =~ s/^(\w)://i; |
27 |
|
|
my $sourcePath_volume = $1; |
28 |
|
|
$sourcePath =~ s/\\/\//g; |
29 |
|
|
#$sourcePath = "/cygdrive/$sourcePath_volume$sourcePath"; |
30 |
|
|
|
31 |
|
|
# strip leading and trailing slash, if any |
32 |
|
|
$sourcePath =~ s/^\///; |
33 |
|
|
$sourcePath =~ s/\/$//; |
34 |
|
|
|
35 |
|
|
# make parts from path |
36 |
|
|
#my @path = split(/\//, $sourcePath); |
37 |
|
|
#my $sourcePath_rel = pop @path; |
38 |
|
|
#my $sourcePath_base = join("/", @path); |
39 |
|
|
|
40 |
|
|
#$sourcePath .= "/" if ($sourcePath !~ /\/$/); |
41 |
|
|
|
42 |
|
|
# main - guess/build destination path |
43 |
|
|
my $hostname = lc $ENV{COMPUTERNAME}; |
44 |
|
|
my $volume = lc $sourcePath_volume; |
45 |
|
|
$hostname ||= "DUMMY"; |
46 |
|
|
$volume ||= "xx"; |
47 |
|
|
my $target_remote = "$remote_ssh_prefix:$remote_target_base/$hostname/$volume/"; |
48 |
|
|
|
49 |
|
|
# main - build rsync command |
50 |
|
|
my $cmd; |
51 |
|
|
$cmd = "$bash -c 'cd /cygdrive/$sourcePath_volume; $rsync -R -azuv -e ssh --progress \"$sourcePath\" \"$target_remote\"'"; |
52 |
|
|
print "synchronizing directories with...", "\n"; |
53 |
|
|
print "cmd: ", $cmd, "\n"; |
54 |
|
|
|
55 |
|
|
# main - run rsync |
56 |
|
|
print `$cmd`; |
57 |
|
|
|
58 |
|
|
print "\n"; |
59 |
|
|
print "sleeping for 1 minute..."; |
60 |
|
|
`sleep 1m`; |
61 |
|
|
|