Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
6
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
D
Drupal Helpers
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Colan Schwartz
Drupal Helpers
Commits
7677171f
Commit
7677171f
authored
Jun 14, 2013
by
Colan Schwartz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added MySQL (or equivalent) backup script for databases.
parent
16379c1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
0 deletions
+71
-0
scripts/mysql-backup-databases
scripts/mysql-backup-databases
+71
-0
No files found.
scripts/mysql-backup-databases
0 → 100755
View file @
7677171f
#!/bin/sh
#############################################################################
# Filename: mysql-backup-databases
# Purpose: To dump all of the mysql databases, compress them, and keep
# a few dumps for some time.
# Author: Colan Schwartz
# Licence: GPLv3
#############################################################################
# Prevent accessing unset variables
set
-u
# Credential file
CRED_FILE
=
/etc/mysql/debian.cnf
# mysqldump opts
OPTS
=
"--single-transaction --skip-lock-tables"
CACHETABLES
=
"cache cache_admin_menu cache_apachesolr cache_block cache_bootstrap cache_content cache_ds_panels cache_field cache_filter cache_form cache_htmlpurifier cache_location cache_luceneapi cache_menu cache_metatag cache_page cache_path cache_rules cache_token cache_update cache_variable cache_views cache_views_data ctools_css_cache ctools_object_cache views_data_export_object_cache views_object_cache"
SCRIPTNAME
=
$(
basename
$0
)
# Set the backup directory.
BACKUPDIR
=
/var/local/backups/mysql
if
[
!
-d
"
$BACKUPDIR
"
]
;
then
logger
"
$SCRIPTNAME
: Destination directory doesn't exist."
mkdir
-p
$BACKUPDIR
fi
# Set the group owner of the dumps
owner_group
=
staff
# Avoid taking all the CPU
#renice +19 -p $$ > /dev/null
# Get the password to connect to MySQL
if
[
-r
"
$CRED_FILE
"
]
;
then
OPTS
=
"--defaults-file=
$CRED_FILE
$OPTS
"
fi
# Make sure that another instance of this script isn't running.
pgrep
$SCRIPTNAME
RET
=
$?
if
[
"
$RET
"
-eq
0
]
;
then
logger
"
$SCRIPTNAME
: Another instance of the process
$SCRIPTNAME
is running, exitting
to avoid multiples instances"
exit
1
fi
# Some DB don't need to be backup
SKIP_BACKUP_LIST
=
"test|temp"
# Get the database names to backup.
DATABASES
=
`
\l
s
-F
/var/lib/mysql |
grep
'\/$'
|
sed
's/\///g'
|
grep
-vwE
$SKIP_BACKUP_LIST
`
# Dump each database and compress it.
for
DATABASE
in
$DATABASES
do
IGNORETABLES
=
$(
for
TABLE
in
$(
echo
$CACHETABLES
)
;
do
echo
-n
" --ignore-table=
$DATABASE
.
$TABLE
"
;
done
;
echo
-n
" "
)
DATE
=
$(
date
"+%y%m%d%H%M"
)
DST_FILE
=
"
$BACKUPDIR
/
$DATABASE
-
$DATE
.sql.gz"
LINK_TARGET
=
"
$BACKUPDIR
/
$DATABASE
-LATEST.sql.gz"
mysqldump
$OPTS
$IGNORETABLES
$DATABASE
|
gzip
>
$DST_FILE
chmod
440
$DST_FILE
chgrp
$owner_group
$DST_FILE
ln
-sf
$DST_FILE
$LINK_TARGET
done
# Delete old backups
KEEP_DAYS
=
60
find
$BACKUPDIR
-maxdepth
1
-type
f
-mtime
+
$KEEP_DAYS
-delete
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