1# -*-perl-*-
2#
3# Backup test of sftp target - set $ENV{BRACKUP_TEST_SFTP} to run
4#
5
6use strict;
7use Test::More;
8
9use Brackup::Test;
10use FindBin qw($Bin);
11use Brackup::Util qw(tempfile);
12
13if ($ENV{BRACKUP_TEST_SFTP}) {
14  plan tests => 25;
15} else {
16  plan skip_all => "\$ENV{BRACKUP_TEST_SFTP} not set";
17}
18
19############### Backup
20
21my ($digdb_fh, $digdb_fn) = tempfile();
22close($digdb_fh);
23my $root_dir = "$Bin/data";
24ok(-d $root_dir, "test data to backup exists");
25my $backup_file = do_backup(
26                            with_confsec => sub {
27                                my $csec = shift;
28                                $csec->add("path",          $root_dir);
29                                $csec->add("chunk_size",    "2k");
30                                $csec->add("digestdb_file", $digdb_fn);
31                            },
32                            with_targetsec => sub {
33                                my $tsec = shift;
34                                $tsec->add("type",          'Sftp');
35                                $tsec->add("sftp_host",     $ENV{SFTP_HOST} || 'localhost');
36                                $tsec->add("sftp_port",     $ENV{SFTP_PORT}) if $ENV{SFTP_PORT};
37                                $tsec->add("sftp_user",     $ENV{SFTP_USER} || '');
38                            },
39                            );
40
41############### Restore
42
43# Full restore
44my $restore_dir = do_restore($backup_file);
45ok_dirs_match($restore_dir, $root_dir);
46
47# --just=DIR restore
48my $just_dir = do_restore($backup_file, prefix => 'my_dir');
49ok_dirs_match($just_dir, "$root_dir/my_dir");
50
51# --just=FILE restore
52my $just_file = do_restore($backup_file, prefix => 'huge-file.txt');
53ok_files_match("$just_file/huge-file.txt", "$root_dir/huge-file.txt");
54
55# --just=DIR/FILE restore
56my $just_dir_file = do_restore($backup_file, prefix => 'my_dir/sub_dir/program.sh');
57ok_files_match("$just_dir_file/program.sh", "$root_dir/my_dir/sub_dir/program.sh");
58
59# vim:sw=4:et
60
61