# cd /tmp
# dbcfg_export -o /tmp/filename.cfg -p "password"
# tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hostkeys | openssl des3 -salt -k "password" | dd of=/tmp/vpn.des3
# tar -zcvf /opt/cdcs/upload/filename.cfg.tar.gz filename.cfg vpn.des3
####
root:/# cd /tmp
root:/tmp# dbcfg_export -o /tmp/test.cfg -p ""
root:/tmp# tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hostkeys | openssl des3 -salt -k "" | dd of=/tmp/vpn.des3
ipsec.d/
ipsec.d/crls/
ipsec.d/aacerts/
ipsec.d/policies/
ipsec.d/cacerts/
ipsec.d/certs/
ipsec.d/rsakey/
ipsec.d/private/
ipsec.d/ocspcerts/
tar: openvpn-keys: Cannot stat: No such file or directory
ssh-hostkeys/
ssh-hostkeys/ssh_host_dsa_key
ssh-hostkeys/ssh_host_rsa_key.pub
ssh-hostkeys/ssh_host_ecdsa_key.pub
ssh-hostkeys/ssh_host_key
ssh-hostkeys/ssh_host_rsa_key
ssh-hostkeys/ssh_host_dsa_key.pub
ssh-hostkeys/ssh_host_key.pub
ssh-hostkeys/ssh_host_ecdsa_key
WARNING: can't open config file: /lib/ssl/openssl.cnf
tar: Exiting with failure status due to previous errors
9+1 records in
9+1 records out
4792 bytes (4.7KB) copied, 0.081756 seconds, 57.2KB/s
root:/tmp# tar -zcvf /opt/cdcs/upload/test.cfg.tar.gz test.cfg vpn.des3
test.cfg
vpn.des3
####
#!/usr/bin/perl -w
###################################### Perl Script ##################################################
## ##
## ##
## Auteur: WILLIAMS Temoe ##
## Date: 21/04/16 ##
## Description: The script will create a backup conf file of a router Netcomm 140W used for business clients ##
## ##
## ##
## ##
#####################################################################################################
use strict;
use warnings;
#### Déclaration Bibliothèques
use Net::SSH2;
use Time::Piece;
#### Déclaration Variables globales
my $date = Time::Piece->new->strftime('%d-%m-%Y');
my $user='root';
my $password='W1m4x21h';
my $portssh=22;
my $pwdfile="";
################# Netcomm140w Backup process via SSH connexion #########################
################# Use router @IP and client name as variables #########################
sub sauvegarde_netcomm {
#### Variable declaration
my($ip, $filename) = @_;
#### Initialize SSH connexion
my $ssh = Net::SSH2->new();
$ssh->connect($ip, $portssh) or die;
if ($ssh->auth_password($user,$password)) {
## Command lines for the backup process
my $chan = $ssh->channel();
$chan->shell();
$chan->blocking(0);
print $chan "cd /tmp\n";
print $chan "dbcfg_export -o /tmp/$filename.cfg -p '$pwdfile'\n";
print $chan "tar -C /usr/local/cdcs -zcvf - ipsec.d openvpn-keys ssh-hostkeys | openssl des3 -salt -k '$pwdfile' | dd of=/tmp/vpn.des3\n";
print $chan "tar -zcvf /opt/cdcs/upload/$filename.cfg.tar.gz $filename.cfg vpn.des3\n";
#print $chan "rm -f /tmp/$filename.cfg\n";
#### Close SSH connexion
$chan->close();
sleep (1);
}else {
#### Error message when ssh connexion fail
warn "auth failed.\n";
}
}
################# Main Program ########################################################
################# Netcomm140w Backup ########################################################
sauvegarde_netcomm ('192.168.200.62' , 'test2');
####
root:/tmp# ll /tmp/t*
-rw-r--r-- 1 root root 31331 Apr 28 13:55 /tmp/test.cfg
-rw-r--r-- 1 root root 31331 Apr 28 13:58 /tmp/test2.cfg
root:/tmp# ll /opt/cdcs/upload/
-rw-r--r-- 1 root root 12548 Apr 28 13:55 test.cfg.tar.gz
-rw-r--r-- 1 root root 20 Apr 28 13:58 test2.cfg.tar.gz