* Improvements to sipwise-cleanup-tools

Changed path for the perl scripts to /usr/sbin
   Cron file added
   Configuration file added
trunk@3605
Jon Bonilla 17 years ago
parent 163afd32da
commit fcb6d0ed35

@ -4,38 +4,37 @@ use strict;
use warnings;
use DBI;
# backing up all data older than $MONTHS months
# Note: if set for example to 1, this will backup the overall month,
# not only the records older than 30 days. This logic applies generally,
# so it will go back $MONTHS months, and starting from there, backing up
# the full months back to $MONTHS_BACK
my $MONTHS = 3;
# from the starting month above, also go back $MONTHS_BACK months and
# backup them
my $MONTHS_BACK = 6;
# archive tables older than $ARCHIVE_MONTHS will be dumped to a file,
# gzipped and then dropped afterwards
my $ARCHIVE_MONTHS = 12;
# drop the dump files into $ARCHIVE_DIR
my $ARCHIVE_DIR = "/tmp";
# accounting database on proxies (openser) or db1 (accounting)
my $ACC_DB = "accounting";
# accounting tables on proxies (acc) or db1 (acc acc_backup acc_trash)
my @ACC_TABLES = qw(acc acc_backup acc_trash);
# cdr database (accounting)
my $CDR_DB = "accounting";
# cdr tables on proxies (empty) or db1 (cdr)
my @CDR_TABLES = qw(cdr);
# how many entries to move and delete at the same time
my $BATCH = 1000;
# DB access credentials
my $DBUSER = "root";
my $DBPASS = "1freibier!";
my $DBHOST = "localhost";
our $MONTHS;
our $MONTHS_BACK;
our $ARCHIVE_MONTHS;
our $ARCHIVE_DIR;
our $ACC_DB;
our $ACC_TABLES;
our $CDR_DB;
our $CDR_TABLES;
our $BATCH;
our $DBUSER;
our $DBPASS;
our $DBHOST;
my $config_file = "/etc/cleanup-tools.conf";
open CONFIG, "$config_file" or die "Program stopping, couldn't open the configuration file '$config_file'.\n";
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
my ($var, $value) = split(/\s*=\s*/, $_, 2);
no strict 'refs';
$$var = $value;
print "El valor de $var es $value - $$var\n"
}
close CONFIG;
########################################################################
@ -119,8 +118,10 @@ sub backup_table {
########################################################################
backup_table(\@ACC_TABLES, $ACC_DB, "time") or die();
backup_table(\@CDR_TABLES, $CDR_DB, "start_time") or die();
archive_dump(\@ACC_TABLES, $ACC_DB);
archive_dump(\@CDR_TABLES, $CDR_DB);
backup_table($ACC_TABLES, $ACC_DB, "time") or die();
backup_table($CDR_TABLES, $CDR_DB, "start_time") or die();
archive_dump($ACC_TABLES, $ACC_DB);
archive_dump($CDR_TABLES, $CDR_DB);

@ -5,9 +5,33 @@ use warnings;
use POSIX;
use DBI;
our $DBUSER;
our $DBPASS;
our $DBREMOTEUSER;
our $DBREMOTEPASS;;
my $config_file = "/etc/cleanup-tools.conf";
open CONFIG, "$config_file" or die "Program stopping, couldn't open the configuration file '$config_file'.\n";
no strict 'refs';
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$$var = $value;
}
use strict 'refs';
close CONFIG;
my (undef, $me) = uname();
my @creds = qw(dbi:mysql: root 1freibier!);
my @remotecreds = qw(dbi:mysql: replicator wait4Data);
my @creds = 'dbi:mysql:'.",".$DBUSER.",".$DBPASS;
my @remotecreds = 'dbi:mysql:'.",".$DBREMOTEUSER.",".$DBREMOTEPASS;
my $dbh = DBI->connect(@creds) or die;

@ -0,0 +1,40 @@
#Sipwise cleanup-tools configuration file
# Note: if set for example to 1, this will backup the overall month,
# not only the records older than 30 days. This logic applies generally,
# so it will go back $MONTHS months, and starting from there, backing up
# the full months back to $MONTHS_BACK
MONTHS = 3
# from the starting month above, also go back $MONTHS_BACK months and
# backup them
MONTHS_BACK = 6
# archive tables older than $ARCHIVE_MONTHS will be dumped to a file,
# gzipped and then dropped afterwards
ARCHIVE_MONTHS = 12
# drop the dump files into $ARCHIVE_DIR
ARCHIVE_DIR = /tmp
# accounting database on proxies (openser) or db1 (accounting)
ACC_DB = accounting
# accounting tables on proxies (acc) or db1 (acc acc_backup acc_trash)
ACC_TABLES = acc,acc_backup,acc_trash
# cdr database (accounting)
CDR_DB = accounting
# cdr tables on proxies (empty) or db1 (cdr)
CDR_TABLES = cdr
# how many entries to move and delete at the same time
BATCH = 1000
# DB access credentials
# Shared by both scripts
DBUSER = root
DBPASS = 1freibier!
DBHOST = localhost
# DB access credentials for binlog cleanup
DBREMOTEUSER = replicator
DBREMOTEPASS = wait4Data

@ -0,0 +1,2 @@
00 03 * * * root /usr/sbin/acc_backup.pl > /dev/null 2>&1
05 03 * * * root /usr/sbin/binlog-purge.pl > /dev/null 2>&1

8
debian/changelog vendored

@ -1,3 +1,11 @@
sipwise-cleanup-tools (0.2-1) unstable; urgency=low
* Config file support added
* Cronjob file added for daily invocation
* Changed install path to /usr/sbin for the scripts
-- Jon Bonilla <jbonilla@sipwise.com> Tue, 13 Oct 2009 23:46:31 +0200
sipwise-cleanup-tools (0.1) unstable; urgency=low
* Initial release.

4
debian/control vendored

@ -11,5 +11,5 @@ Vcs-Browser: https://dev.sipwise.com/svn/voip-tools/cleanup-tools
Package: sipwise-cleanup-tools
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}
Description: TODO
TODO
Description: Database entry and binlog cleanup
Erase and dump databse entries and mysql binlogs

6
debian/rules vendored

@ -30,8 +30,10 @@ install: build
dh_installdirs usr/bin
# Add here commands to install the package into debian/sipwise-cleanup-tools.
install -m 755 acc_backup.pl debian/sipwise-cleanup-tools/usr/bin/acc_backup.pl
install -m 755 binlog-purge.pl debian/sipwise-cleanup-tools/usr/bin/binlog-purge.pl
install -m 755 acc_backup.pl debian/sipwise-cleanup-tools/usr/sbin/acc_backup.pl
install -m 755 binlog-purge.pl debian/sipwise-cleanup-tools/usr/sbin/binlog-purge.pl
install -m 644 cleanup-tools.conf debian/sipwise-cleanup-tools/etc/cleanup-tools.conf
install -m 644 cleanup-tools.cron debian/sipwise-cleanup-tools/etc/cron.d/cleanup-tools
# Build architecture-dependent files here.
binary-arch: install

Loading…
Cancel
Save