Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
emulab
emulab-devel
Commits
3f326ae6
Commit
3f326ae6
authored
Jan 16, 2001
by
Leigh B. Stoller
Browse files
Clean up and modify so that mail is sent only when the backup fails.
parent
04cecbac
Changes
1
Hide whitespace changes
Inline
Side-by-side
db/backup.in
View file @
3f326ae6
...
...
@@ -10,7 +10,7 @@ my $DBNAME = "@TBDBNAME@";
my
$BACKUPDIR
=
"
$TB
/backup
";
# un-taint path
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin
';
$ENV
{'
PATH
'}
=
'
/bin:/usr/bin:/usr/local/bin
:/usr/site/bin
';
delete
@ENV
{'
IFS
',
'
CDPATH
',
'
ENV
',
'
BASH_ENV
'};
#
...
...
@@ -21,11 +21,6 @@ if ($UID != 0) {
exit
(
-
1
);
}
if
(
!
chdir
(
$BACKUPDIR
))
{
print
STDERR
"
Could not chdir to
$BACKUPDIR
!
\n
";
exit
(
-
1
);
}
#
# Format the name of the backup with date.
# Untaint it since it was constructed with date. Dopey.
...
...
@@ -36,21 +31,57 @@ if ($name =~ /^([-\@\w.]+)$/) {
$name
=
$
1
;
}
#
# Create a temporary name for a log file and untaint it.
#
#
# Form a temp name.
#
my
$logname
=
`
mktemp /tmp/dbbackup.XXXXXX
`;
if
(
$logname
=~
/^([-\@\w.\/]+)$/
)
{
$logname
=
$
1
;
}
else
{
die
"
Bad data in
$logname
";
}
#
# Turn off line buffering on output
#
$|
=
1
;
#
# Reopen both stdout and stderr so that we can record all the output for
# later mailing.
#
open
(
STDERR
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDERR: $!
");
open
(
STDOUT
,
"
>>
$logname
")
or
die
("
opening
$logname
for STDOUT: $!
");
if
(
!
chdir
(
$BACKUPDIR
))
{
print
STDERR
"
Could not chdir to
$BACKUPDIR
!
\n
";
fatal
();
}
#
# Do a mysqldump. This will reset the log files.
#
if
(
system
("
mysqldump --all --flush-logs --lock-tables
$DBNAME
>
$name
"))
{
print
STDERR
"
mysqldump failed!
\n
";
exit
(
1
);
fatal
(
);
}
#
# Compress it.
#
if
(
system
("
gzip
$name
"))
{
print
STDERR
"
gzip failed!
\n
";
exit
(
1
);
fatal
(
);
}
print
STDOUT
"
DB backup (
$DBNAME
) complete!
\n
";
#system("cat $logname | /usr/bin/mail -s '\"DB Backup Finished\"' stoller");
unlink
("
$logname
");
exit
0
;
sub
fatal
{
system
("
cat
$logname
| /usr/bin/mail
"
.
"
-s '
\"
DB Backup Failed
\"
' testbed
@fast
");
unlink
("
$logname
");
exit
(
1
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment