Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emulab-devel
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
111
Issues
111
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
emulab
emulab-devel
Commits
3f326ae6
Commit
3f326ae6
authored
Jan 16, 2001
by
Leigh Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Showing
1 changed file
with
43 additions
and
12 deletions
+43
-12
db/backup.in
db/backup.in
+43
-12
No files found.
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
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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