diff options
Diffstat (limited to 'scripts/vyatta-save-config.pl')
-rwxr-xr-x | scripts/vyatta-save-config.pl | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl new file mode 100755 index 0000000..ad972b4 --- /dev/null +++ b/scripts/vyatta-save-config.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfigOutput; + +my $sbindir = $ENV{ofr_sbindir}; +my $etcdir = $ENV{ofr_sysconfdir}; +my $bootfile = ''; +if (-r "$etcdir/bootfile_path") { + $bootfile = `cat $etcdir/bootfile_path`; +} +my $bootpath = $bootfile; +$bootpath =~ s/\/[^\/]+$//; + +if ($#ARGV > 0) { + print "Usage: save [config_file_name]\n"; + exit 1; +} + +my $save_file = "$bootfile"; +if (defined($ARGV[0])) { + $save_file = $ARGV[0]; + if (!($save_file =~ /^\//)) { + # relative path + $save_file = "$bootpath/$save_file"; + } +} + +# this overwrites the file if it exists. we could create a backup first. +if (! open(SAVE, ">$save_file")) { + print "Cannot open file '$save_file': $!\n"; + exit 1; +} + +print "Saving configuration to '$save_file'..."; +select SAVE; +VyattaConfigOutput::outputActiveConfig(); +my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; +print SAVE $version_str; +select STDOUT; +print "\nDone\n"; +close SAVE; +exit 0; + |