diff options
author | Stig Thormodsrud <stig@vyatta.com> | 2010-11-05 15:19:21 -0700 |
---|---|---|
committer | Stig Thormodsrud <stig@vyatta.com> | 2010-11-05 15:19:21 -0700 |
commit | a60321f3b38c93b200ff2705eebd4d274cda895d (patch) | |
tree | 86b3d04e5f6f983dce8f6f2a1059a278632bb9b1 | |
parent | 9f32a72037fdc5cb3abbfa97adb4f612920847dc (diff) | |
download | vyatta-config-mgmt-a60321f3b38c93b200ff2705eebd4d274cda895d.tar.gz vyatta-config-mgmt-a60321f3b38c93b200ff2705eebd4d274cda895d.zip |
Don't save a rev if the file hasn't changed.
-rw-r--r-- | lib/Vyatta/ConfigMgmt.pm | 21 | ||||
-rwxr-xr-x | scripts/vyatta-commit-revs.pl | 13 | ||||
-rwxr-xr-x | scripts/vyatta-config-mgmt.pl | 2 |
3 files changed, 24 insertions, 12 deletions
diff --git a/lib/Vyatta/ConfigMgmt.pm b/lib/Vyatta/ConfigMgmt.pm index 6a49af3..a23b82b 100644 --- a/lib/Vyatta/ConfigMgmt.pm +++ b/lib/Vyatta/ConfigMgmt.pm @@ -30,7 +30,7 @@ our @EXPORT = qw(cm_commit_add_log cm_commit_get_log cm_get_archive_dir cm_get_lr_conf_file cm_get_lr_state_file cm_get_commit_hook_dir cm_write_file cm_read_file cm_commit_get_file cm_commit_get_file_name - cm_get_num_revs); + cm_get_num_revs cm_get_last_commit_file); use base qw(Exporter); use Vyatta::Config; @@ -40,13 +40,14 @@ use POSIX; use IO::Zlib; -my $commit_hook_dir = '/etc/commit/'; -my $config_dir = '/opt/vyatta/etc/config'; -my $archive_dir = "$config_dir/archive"; -my $config_file = "$config_dir/config.boot"; -my $lr_conf_file = "$archive_dir/lr.conf"; -my $lr_state_file = "$archive_dir/lr.state"; -my $commit_log_file = "$archive_dir/commits"; +my $commit_hook_dir = '/etc/commit/'; +my $config_dir = '/opt/vyatta/etc/config'; +my $archive_dir = "$config_dir/archive"; +my $config_file = "$config_dir/config.boot"; +my $lr_conf_file = "$archive_dir/lr.conf"; +my $lr_state_file = "$archive_dir/lr.state"; +my $commit_log_file = "$archive_dir/commits"; +my $last_commit_file = "$archive_dir/config.boot"; sub cm_get_commit_hook_dir { @@ -65,6 +66,10 @@ sub cm_get_lr_state_file { return $lr_state_file; } +sub cm_get_last_commit_file { + return $last_commit_file; +} + sub cm_read_file { my ($file) = @_; my @lines; diff --git a/scripts/vyatta-commit-revs.pl b/scripts/vyatta-commit-revs.pl index 7ae34ad..edf0845 100755 --- a/scripts/vyatta-commit-revs.pl +++ b/scripts/vyatta-commit-revs.pl @@ -34,21 +34,26 @@ use lib '/opt/vyatta/share/perl5/'; use Vyatta::Config; use Vyatta::ConfigMgmt; +use File::Compare; # # main # -my $archive_dir = cm_get_archive_dir(); -my $lr_state_file = cm_get_lr_state_file(); -my $lr_conf_file = cm_get_lr_conf_file(); +my $archive_dir = cm_get_archive_dir(); +my $lr_state_file = cm_get_lr_state_file(); +my $lr_conf_file = cm_get_lr_conf_file(); +my $last_commit_file = cm_get_last_commit_file(); +my $tmp_config_file = "/tmp/config.boot.$$"; if (! -d $archive_dir) { system("sudo mkdir $archive_dir"); } -my $tmp_config_file = "/tmp/config.boot.$$"; system("/opt/vyatta/sbin/vyatta-save-config.pl $tmp_config_file > /dev/null"); +if (compare($tmp_config_file, $last_commit_file) == 0) { + exit 0; +} system("sudo mv $tmp_config_file $archive_dir/config.boot"); system("sudo logrotate -f -s $lr_state_file $lr_conf_file"); my ($user) = getpwuid($<); diff --git a/scripts/vyatta-config-mgmt.pl b/scripts/vyatta-config-mgmt.pl index 46d57e9..94b9b57 100755 --- a/scripts/vyatta-config-mgmt.pl +++ b/scripts/vyatta-config-mgmt.pl @@ -142,11 +142,13 @@ if ($action eq 'update-revs') { } if (! -e $archive_dir) { system("sudo mkdir $archive_dir"); + system("sudo chown vyatta:vyattacfg $archive_dir"); } my $lr_conf = "$config_file {\n"; $lr_conf .= "\t rotate $revs\n"; $lr_conf .= "\t start 0\n"; $lr_conf .= "\t compress \n"; + $lr_conf .= "\t copy \n"; $lr_conf .= "}\n"; cm_write_file($lr_conf_file, $lr_conf); exit 0; |