-
Notifications
You must be signed in to change notification settings - Fork 5
/
sync-mydocs
executable file
·74 lines (58 loc) · 1.2 KB
/
sync-mydocs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use strict;
use warnings;
sub run(@);
my $dir = "$ENV{HOME}/Code/n9";
my $myDocsLocal = "$dir/backup/MyDocs";
my $myDocsRemote = "/home/user/MyDocs";
my @excludes = map {"--exclude=$_"} qw(
monav_data
DCIM
DCIM-pixmirror
Music
email
backup-contacts
backup-sms
backup-sms-repo
backup-call
backup-call-repo
backup-tracker
cities
DevIcon.fil
ignored/
Playlists
pvr_hwrec
.thumbnails/
.qf
.wallpapers/
lost+found
);
my @rsyncOpts = qw(
-a --no-owner --no-group
-v -P
);
sub main(@){
my $overwrite = 0;
$overwrite = shift if @_ == 1 and $_[0] =~ /--overwrite/;
die "Usage: $0 [--overwrite]\n" if @_ > 0;
my $host = `n9`;
chomp $host;
my $local = $myDocsLocal;
my $remote = "user\@$host:$myDocsRemote";
if($overwrite){
run "rsync", @rsyncOpts, @excludes, "$local/", $remote, "--del", "-n";
print "dryrun ok? [Y/n] ";
if(<STDIN> !~ /n/){
run "rsync", @rsyncOpts, @excludes, "$local/", $remote, "--del";
}
}else{
run "rsync", @rsyncOpts, @excludes, "$remote/", $local;
run "rsync", @rsyncOpts, @excludes, "$local/", $remote;
}
}
sub run(@){
print "@_\n";
system @_;
die "failed" if $? != 0;
}
&main(@ARGV);