#!/usr/bin/perl use strict; use warnings; my $backup_dir = '/tmp'; # on windows use something like this: C:/home/dir my $workspace_dir = '.'; my $SVN = 'svn'; # path to subversion client executable ########################################### use Getopt::Long qw(GetOptions); use File::Basename qw(); use File::Copy qw(); use File::Path qw(); use File::Spec qw(); use POSIX qw(); my $VERSION = '0.02'; my $time = POSIX::strftime("%Y-%m-%d-%H-%M-%S",localtime()); my $help; GetOptions( "backup=s" => \$backup_dir, "workspace=s" => \$workspace_dir, "help" => \$help, ) or usage(); usage() if $help; my @out = `$SVN st "$workspace_dir"`; #print @out; chomp @out; foreach my $line (@out) { #if (substr($line, 0, 2) =~ /[^? ]/) { #print "$line\n"; my $path = substr($line, 7); my $dir = File::Basename::dirname($path) || ''; my $file = File::Basename::basename($path); my $full_path = File::Spec->catfile($backup_dir, $time, $dir); if (not $dir) { $full_path = File::Spec->catfile($backup_dir, $time); } File::Path::mkpath($full_path); # TODO: remove full path #my $workfile = File::Spec->catfile($workspace_dir, $path); my $backupfile = File::Spec->catfile($full_path, $file); $backupfile =~ s/://g; #print "copy $workfile, $backupfile\n"; print "copy $path, $backupfile\n"; #File::Copy::copy($workfile, $backupfile) or die $!; #} } sub usage { print <<"END_USAGE"; Version: $VERSION Usage: $0 --backup BACKUP_DIRECTORY --workspace WORKSPACE_DIRECTORY (defaults to .) --help this help END_USAGE exit; }