[vhffs-dev] [1966] first step of archives for each deleted object, added Vhffs::Robots: :archive_targz() helper, migrated mail box delete |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [1966] first step of archives for each deleted object, added Vhffs::Robots: :archive_targz() helper, migrated mail box delete
- From: subversion@xxxxxxxxxxxxx
- Date: Sat, 28 Jan 2012 23:30:32 +0100
Revision: 1966
Author: gradator
Date: 2012-01-28 23:30:31 +0100 (Sat, 28 Jan 2012)
Log Message:
-----------
first step of archives for each deleted object, added Vhffs::Robots::archive_targz() helper, migrated mail box delete
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Constants.pm
trunk/vhffs-api/src/Vhffs/Functions.pm
trunk/vhffs-api/src/Vhffs/Robots.pm
trunk/vhffs-backend/conf/vhffs.conf.dist.in
trunk/vhffs-robots/src/mail_deleteboxes.pl
Modified: trunk/vhffs-api/src/Vhffs/Constants.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Constants.pm 2012-01-28 16:25:07 UTC (rev 1965)
+++ trunk/vhffs-api/src/Vhffs/Constants.pm 2012-01-28 22:30:31 UTC (rev 1966)
@@ -85,6 +85,7 @@
};
use constant {
+ # Status strings that are going to be read by humans
STATUS_STRINGS => {
Vhffs::Constants::WAITING_FOR_VALIDATION => 'Waiting for validation',
Vhffs::Constants::VALIDATION_REFUSED => 'Validation refused',
@@ -99,6 +100,7 @@
Vhffs::Constants::MODIFICATION_APPLIED => 'Modification applied',
Vhffs::Constants::TO_DELETE => 'Will be deleted',
},
+ # Types strings that are going to be read by humans
TYPES_STRINGS => {
Vhffs::Constants::TYPE_USER => 'User',
Vhffs::Constants::TYPE_GROUP => 'Group',
@@ -116,6 +118,24 @@
Vhffs::Constants::TYPE_ML => 'Mailing List',
Vhffs::Constants::TYPE_CRON => 'Cron job',
},
+ # Types strings that are convenient for file systems (no space, lowercase)
+ TYPES_STRINGS_FS => {
+ Vhffs::Constants::TYPE_USER => 'user',
+ Vhffs::Constants::TYPE_GROUP => 'group',
+ Vhffs::Constants::TYPE_WEB => 'web',
+ Vhffs::Constants::TYPE_REPOSITORY => 'repository',
+ Vhffs::Constants::TYPE_MYSQL => 'mysql',
+ Vhffs::Constants::TYPE_PGSQL => 'postgresql',
+ Vhffs::Constants::TYPE_CVS => 'cvs',
+ Vhffs::Constants::TYPE_SVN => 'svn',
+ Vhffs::Constants::TYPE_GIT => 'git',
+ Vhffs::Constants::TYPE_MERCURIAL => 'mercurial',
+ Vhffs::Constants::TYPE_BAZAAR => 'bazaar',
+ Vhffs::Constants::TYPE_DNS => 'dns',
+ Vhffs::Constants::TYPE_MAIL => 'mail',
+ Vhffs::Constants::TYPE_ML => 'mailinglist',
+ Vhffs::Constants::TYPE_CRON => 'cron',
+ },
};
1;
Modified: trunk/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Functions.pm 2012-01-28 16:25:07 UTC (rev 1965)
+++ trunk/vhffs-api/src/Vhffs/Functions.pm 2012-01-28 22:30:31 UTC (rev 1966)
@@ -396,6 +396,11 @@
return gettext( Vhffs::Constants::TYPES_STRINGS->{$type} or 'Unknown');
}
+sub type_string_fs_from_type_id($) {
+ my $type = shift;
+ return gettext( Vhffs::Constants::TYPES_STRINGS_FS->{$type} or 'unknown');
+}
+
=pod
=head2 check_domain_name
Modified: trunk/vhffs-api/src/Vhffs/Robots.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots.pm 2012-01-28 16:25:07 UTC (rev 1965)
+++ trunk/vhffs-api/src/Vhffs/Robots.pm 2012-01-28 22:30:31 UTC (rev 1966)
@@ -39,6 +39,8 @@
my @ISA = qw(Exporter);
my @EXPORT = qw(vhffs_log lock unlock);
+use Cwd;
+
use Vhffs::Functions;
use Vhffs::Main;
use LockFile::Simple qw(lock trylock unlock);
@@ -140,6 +142,43 @@
return 1;
}
+sub archive_targz {
+ my $vhffs = shift;
+ my $object = shift;
+ my $dir = shift;
+ my $namepart = shift;
+ my $ret;
+
+ return undef unless defined $dir and -d $dir;
+
+ my $robotconf = $vhffs->get_config->get_robots;
+ return undef unless defined $robotconf and Vhffs::Functions::strtobool( $robotconf->{'archive_deleted'} ) and defined $robotconf->{'archive_deleted_path'} and -d $robotconf->{'archive_deleted_path'};
+
+ my $oldcwd = getcwd();
+ return undef unless chdir($dir);
+
+ my $tarfile = $robotconf->{'archive_deleted_path'}.'/'.time().'_'.$object->get_group->get_groupname.'_'.Vhffs::Functions::type_string_fs_from_type_id( $object->get_type ).'_'.$object->get_label.'_'.join('_', @$namepart).'.tar.gz';
+ my $childpid = open( my $output, '-|', 'tar', 'czf', $tarfile, '.' );
+ if ($childpid) {
+ # read process output then discard
+ while(<$output>) {}
+
+ # wait for the child to finish
+ waitpid( $childpid, 0 );
+
+ # $? contains the return value, The high byte is the exit value of the process. The low 7 bits represent
+ # the number of the signal that killed the process, with the 8th bit indicating whether a core dump occurred.
+ # -- signal is 0 if no signal were sent to kill the process
+ # -- exit value is 0 if the process success
+ # -- core dump bit is 0 if no core dump were written to disk
+ # ---- so, $? contains 0 if everything went fine
+ $ret = $? >> 8 if $?;
+ }
+
+ chdir($oldcwd);
+ return not defined $ret and -f $tarfile ? 1 : undef;
+}
+
1;
__END__
Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in 2012-01-28 16:25:07 UTC (rev 1965)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in 2012-01-28 22:30:31 UTC (rev 1966)
@@ -632,6 +632,18 @@
# One lock will be created per robot, you can still run robots simultaneously
use_lock = yes
lockfile = /var/lock/vhffs
+
+ # Should we archive (.tar.gz and/or .dump.gz) deleted services ?
+ # This way, user mistakes can be handled easily
+ archive_deleted = yes
+
+ # Complete path to archive directory
+ # Archives will be put into $archive_path/$unixtimestamp_groupname_servicetype_servicename.(tar|dump).gz
+ archive_deleted_path = /data/archives
+
+ # How long should we keep archives of deleted objects,
+ # value in days, set this to 0 to never delete archives
+ archive_deleted_ttl = 0
</robots>
Modified: trunk/vhffs-robots/src/mail_deleteboxes.pl
===================================================================
--- trunk/vhffs-robots/src/mail_deleteboxes.pl 2012-01-28 16:25:07 UTC (rev 1965)
+++ trunk/vhffs-robots/src/mail_deleteboxes.pl 2012-01-28 22:30:31 UTC (rev 1966)
@@ -52,22 +52,17 @@
foreach my $b ( @{$boxes} )
{
my $mail = Vhffs::Services::Mail::get_by_mxdomain( $vhffs, $b->{domain} );
- if( defined $mail ) {
+ next unless defined $mail;
- my $dir = $mail->get_box_dir( $b->{local_part} );
- if( -d $dir && chdir($dir) ) {
- if( defined $mailconf->{'archives_dir'} && -d $mailconf->{'archives_dir'} ) {
- my $cmd = 'tar cf '.$mailconf->{'archives_dir'}.'/'.time().'_'.$b->{local_part}.'@'.$b->{domain}.'.tar . 1> /dev/null 2> /dev/null';
- system( $cmd );
- }
- # File::Path::rmtree abort if $dir is cwd
- chdir('..');
- File::Path::rmtree($dir);
- # Remove the letter/ directory if empty
- rmdir dirname($dir);
- }
- $mail->delbox( $b->{local_part} );
+ my $dir = $mail->get_box_dir( $b->{local_part} );
+ Vhffs::Robots::archive_targz( $vhffs, $mail, $dir, [ $b->{local_part} ] );
+
+ if( -d $dir ) {
+ File::Path::rmtree($dir);
+ # Remove the letter/ directory if empty
+ rmdir dirname($dir);
}
+ $mail->delbox( $b->{local_part} );
}
Vhffs::Robots::unlock( $vhffs , 'mail' );