add backup restore script
This commit is contained in:
parent
cf35982fb3
commit
7272ce4fad
45
mysql-backup/backup.sh
Executable file
45
mysql-backup/backup.sh
Executable file
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get real path of softlink
|
||||||
|
get_real_path() {
|
||||||
|
local f="$1"
|
||||||
|
while [ -h "$f" ]; do
|
||||||
|
ls=`ls -ld "$f"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
f="$link"
|
||||||
|
else
|
||||||
|
f=`dirname "$f"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
eval "$2"="'$f'"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_real_path "$0" prg_path
|
||||||
|
echo "Script Path [$prg_path]"
|
||||||
|
|
||||||
|
# Service Home
|
||||||
|
pushd $(dirname "$prg_path") > /dev/null
|
||||||
|
SERVICE_HOME=$(dirname $(pwd))
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
# enter service home
|
||||||
|
pushd "$SERVICE_HOME"
|
||||||
|
|
||||||
|
time=$(date '+%Y%m%d%H%M%S')
|
||||||
|
|
||||||
|
database='ambition_crm'
|
||||||
|
db_user='root'
|
||||||
|
db_password='696@2^~)oZ@^#*Q'
|
||||||
|
backup_dir="$SERVICE_HOME/backup/$database"
|
||||||
|
|
||||||
|
# create backup dir if not exists
|
||||||
|
[ ! -e "$backup_dir" ] && mkdir -p "$backup_dir"
|
||||||
|
|
||||||
|
mysqldump -u"$db_user" -p"$db_password" "$database" | gzip > "$backup_dir/${time}.sql.gz"
|
||||||
|
|
||||||
|
# remove 30 days ago backups
|
||||||
|
find "$backup_dir" -name "*.sql.gz" -type f -mtime +30 -exec rm -rf {} \; > /dev/null 2>&1
|
||||||
|
|
||||||
|
# back to previous dir
|
||||||
|
popd > /dev/null
|
41
mysql-backup/restore.sh
Executable file
41
mysql-backup/restore.sh
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# get real path of softlink
|
||||||
|
get_real_path() {
|
||||||
|
local f="$1"
|
||||||
|
while [ -h "$f" ]; do
|
||||||
|
ls=`ls -ld "$f"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
f="$link"
|
||||||
|
else
|
||||||
|
f=`dirname "$f"`/"$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
eval "$2"="'$f'"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_real_path "$0" prg_path
|
||||||
|
echo "Script path [$prg_path]"
|
||||||
|
|
||||||
|
# Service Home
|
||||||
|
pushd $(dirname "$prg_path") > /dev/null
|
||||||
|
SERVICE_HOME=$(dirname $(pwd))
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
# enter service home
|
||||||
|
pushd "$SERVICE_HOME"
|
||||||
|
database=ambition_crm
|
||||||
|
|
||||||
|
backup_dir="$SERVICE_HOME/backup/$database"
|
||||||
|
restore_file="$backup_dir/${1}.sql.gz"
|
||||||
|
# exit when file not found
|
||||||
|
if [ ! -f "$restore_file" ]; then
|
||||||
|
echo "no restore file [$restore_file] found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
< "$restore_file" gzip -dc | mysql ambition_crm_test
|
||||||
|
|
||||||
|
# back to previous dir
|
||||||
|
popd > /dev/null
|
@ -27,7 +27,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button data-rel="tooltip" class="btn btn-xs btn-info" title="Restore" {{action (route-action 'restore' it)}}>
|
<button data-rel="tooltip" class="btn btn-xs btn-info" title="Restore" {{action (route-action 'restore' it)}}>
|
||||||
<i class="ace-icon fa fa-reply-all bigger-120"></i>
|
<i class="ace-icon fa fa-undo bigger-120"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user