smeserver-manager/root/usr/share/smanager/themes/default/templates/backdown.html.ep

57 lines
1.6 KiB
Plaintext
Raw Normal View History

<%
my $backups = esmith::BackupHistoryDB->open;
my $now = time();
my $backup_rec = $backups->new_record($now, {
type => 'backup_record', BackupType => 'desktop',
StartEpochTime => $now,
});
# Dump the current mysql tables so that they are part of the image.
# The events handle cases where mysqld is not enabled, and/or is not running.
my $status = system("/sbin/e-smith/signal-event", "pre-backup", "desktop");
if ($status) {
desktopBackupRecordStatus($backup_rec, 'pre-backup', $status);
return ($c->l('bac_OPERATION_STATUS_REPORT').
$c->l('bac_ERR_PRE_BACKUP'));
}
my $clvl = $c->stash('compressionlevel');
my $cmd = "/bin/tar --directory / --create @{$c->stash('directories')} --file=-"
. "@{$c->stash('exclude')} | /usr/bin/gzip $clvl ";
my $success = open my $fh, '-|', $cmd;
unless ($success) { return "Error dowload command."; };
# Write chunk
$c->res->headers->content_type('application/x-tar');
$c->res->headers->content_disposition(qq/attachment; filename="smeserver.tgz"/);
my $cb;
$cb = sub {
my $c = shift;
my $size = 500 * 1024;
my $length = sysread($fh, my $buffer, $size);
unless ($length) {
close $fh;
undef $cb;
$c->finish;
return;
}
$c->write_chunk($buffer, $cb);
};
$c->$cb;
# Remove the dumped tables.
$status = system("/sbin/e-smith/signal-event", "post-backup", "desktop");
if ($status) {
desktopBackupRecordStatus($backup_rec, 'post-backup', $status);
die ($c->l('bac_ERR_POST_BACKUP'),"\n");
}
$now = time();
$backup_rec->set_prop('EndEpochTime', "$now");
$backup_rec->set_prop('Result', "0");
%>