Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mysql
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ansible
mysql
Commits
a42b035e
Commit
a42b035e
authored
9 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Universal backup script (doesn't have to know about databases before running).
parent
0394c826
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
files/backup.sh
+21
-0
21 additions, 0 deletions
files/backup.sh
tasks/main.yml
+11
-5
11 additions, 5 deletions
tasks/main.yml
templates/mysql.j2
+0
-2
0 additions, 2 deletions
templates/mysql.j2
with
32 additions
and
7 deletions
files/backup.sh
0 → 100644
+
21
−
0
View file @
a42b035e
#!/bin/sh -e
# Back up all databases, each to a seperate file.
backup
()
{
mysqldump
--defaults-file
=
/etc/mysql/debian.cnf
\
--single-transaction
\
--force
\
--result-file
=
/var/backups/mysql_
$1
.sql
$1
}
# TODO: Find a way to remove table formatting from this command.
#alias show='mysqlshow --defaults-file=/etc/mysql/debian.cnf'
alias
show
=
"mysql --defaults-file=/etc/mysql/debian.cnf -e 'show databases;'"
# The reason for dropping the first 4 lines is that the first line is the
# heading and 3 following lines are databases internal to MySQL and thus their
# backup is not needed.
for
database
in
$(
show |
tail
-n
+5
)
do
backup
$database
done
This diff is collapsed.
Click to expand it.
tasks/main.yml
+
11
−
5
View file @
a42b035e
...
@@ -24,23 +24,29 @@
...
@@ -24,23 +24,29 @@
-
cron
-
cron
-
name
:
Create database
-
name
:
Create database
when
:
mysql_database is defined
mysql_db
:
mysql_db
:
login_user
:
root
login_password
:
'
{{
mysql_root_password
}}'
collation
:
utf8_general_ci
collation
:
utf8_general_ci
encoding
:
utf8
encoding
:
utf8
name
:
'
{{
mysql_database
}}'
name
:
'
{{
mysql_database
}}'
state
:
present
state
:
present
-
name
:
Create account
-
name
:
Create account
when
:
mysql_user is defined and mysql_database is defined
mysql_user
:
mysql_user
:
login_user
:
root
login_password
:
'
{{
mysql_root_password
}}'
name
:
'
{{
mysql_user
}}'
name
:
'
{{
mysql_user
}}'
password
:
'
{{
mysql_password
}}'
password
:
'
{{
mysql_password
|default(omit)
}}'
priv
:
'
{{
mysql_database
}}.*:SELECT,INSERT,UPDATE,DELETE,CREATE,INDEX'
priv
:
'
{{
mysql_database
}}.*:SELECT,INSERT,UPDATE,DELETE,CREATE,INDEX'
state
:
present
state
:
present
-
name
:
Add daily backup job
-
name
:
Add daily backup job
template
:
copy
:
src
:
mysql.j2
src
:
backup.sh
dest
:
'
/etc/cron.daily/mysql
_{{
mysql_database
}}'
dest
:
/etc/cron.daily/mysql
owner
:
root
owner
:
root
group
:
root
group
:
root
mode
:
'
07
00
'
mode
:
'
07
55
'
This diff is collapsed.
Click to expand it.
templates/mysql.j2
deleted
100644 → 0
+
0
−
2
View file @
0394c826
#!/bin/sh -e
mysqldump
--user
root
--password
{{
mysql_root_password
}}
--single-transaction
--force
{{
mysql_database
}}
>
/var/backups/mysql_
{{
mysql_database
}}
.sql
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment