Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3695546
bak-mysql.sh
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
dereckson
Oct 26 2024, 23:42
2024-10-26 23:42:09 (UTC+0)
Size
1 KB
Referenced Files
None
Subscribers
None
bak-mysql.sh
View Options
#!/bin/sh
# -------------------------------------------------------------
# Backup MariaDB or MySQL databases
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# License: BSD-2-Clause
# -------------------------------------------------------------
set
-e
BACKUP_DIR
=
/var/backups/db
# -------------------------------------------------------------
# Ensure user is root
#
# Note: POSIX shells don't always define $UID or $EUID.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
[
"
${
EUID
:-$(
id -u
)
}
"
-ne
0
]
;
then
echo
"This command must be run as root."
>
&
2
exit
1
fi
# -------------------------------------------------------------
# Collect information
#
# :: Databases to dump
# :: Timestamp
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
DATABASES
=
$(
mysql -Ns -e
"show databases"
|
grep -v -E
'information_schema|performance_schema|mysql-innodb-'
)
SUBDIR
=
$(
hostname -s
)
-
$(
date +
"%s"
)
mkdir
"
$BACKUP_DIR
/
$SUBDIR
"
for
database in
$DATABASES
;
do
mysqldump
$database
|
gzip >
"
$BACKUP_DIR
/
$SUBDIR
/
$database
.sql.gz"
done
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2218845
Default Alt Text
bak-mysql.sh (1 KB)
Attached To
Mode
P367 bak-mysql.sh
Attached
Detach File
Event Timeline
Log In to Comment