Skip to content

Commit

Permalink
mydumper
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyclenerd committed Oct 15, 2022
1 parent 6fe1cb9 commit 4f5466e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,27 @@ Used in Ansible Playbook:
line: "MY_DIR={{ mysql_backup_dir }}"
```

## MyDumper

* `mydumper.sh` - Run `mydumper` and save either in folder `[NUMBER]A` or `[NUMBER]B`.

Used in Ansible Playbook:
```yml
- name: MyDumper - Download script
ansible.builtin.get_url:
url: https://raw.githubusercontent.com/Cyclenerd/toolbox/master/mydumper.sh
dest: /root/mydumper.sh
mode: '0755'
owner: root
group: root
- name: MyDumper - Change MY_DIR in script
ansible.builtin.lineinfile:
path: /root/mydumper.sh
regexp: '^MY_DIR'
line: "MY_DIR={{ mysql_backup_dir }}"
```

## License

GNU Public License version 3.
Expand Down
92 changes: 92 additions & 0 deletions mydumper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

# Run mydumper and save either in folder [NUMBER]A or [NUMBER]B.
# If successful, delete the other folder (A or B).

# Configuration file ~/.my.conf:
#
# [mydumper]
# host=127.0.0.1
# user=root
# password=[PASSWORD]
#
# [myloader]
# host=127.0.0.1
# user=root
# password=[PASSWORD]

ME=$(basename "$0")
MY_DIR="/mnt/usb_wd_4tb_crypt/backup"

function usage {
returnCode="$1"
echo
echo -e "Usage:
$ME -d <DIR> -n <NUMBER>] [-h]
-d <DIR> Backup directory (Default: '$MY_DIR')
-n <NUMBER> Folder number
[-h] Displays help (this message)"
echo
exit "$returnCode"
}

while getopts "d:n:h" opt; do
case $opt in
d)
MY_DIR="$OPTARG"
;;
n)
MY_NUMBER="$OPTARG"
;;
h)
usage 0
;;
*)
usage 1
;;
esac
done

command -v mydumper >/dev/null 2>&1 || { echo >&2 "!!! Error !!! mydumper it's not installed."; exit 1; }

if ((MY_NUMBER >= 1)); then
echo "Folder number: $MY_NUMBER"
else
echo "Folder number for backup missing"
exit 3
fi

if [ -d "$MY_DIR" ]; then
MY_DIR=${MY_DIR%/}
echo "Backup dir: $MY_DIR"
else
echo "Backup dir missing or directory '$MY_DIR' does not exists."
exit 2
fi

MY_BACKUP_DIR_A="$MY_DIR""/""$MY_NUMBER""A"
MY_BACKUP_DIR_B="$MY_DIR""/""$MY_NUMBER""B"

if [ -d "$MY_BACKUP_DIR_A" ]; then
mkdir -p "$MY_BACKUP_DIR_B"
echo "Backup to: $MY_BACKUP_DIR_B"
if mydumper --outputdir "$MY_BACKUP_DIR_B"; then
echo "Success. Delete old backup."
rm -rf "$MY_BACKUP_DIR_A"
else
echo "!!! Error !!! Delete current and errored backup."
rm -rf "$MY_BACKUP_DIR_B"
exit 9
fi
else
mkdir -p "$MY_BACKUP_DIR_A"
echo "Backup to: $MY_BACKUP_DIR_A"
if mydumper --outputdir "$MY_BACKUP_DIR_A"; then
echo "Success. Delete old backup."
rm -rf "$MY_BACKUP_DIR_B"
else
echo "!!! Error !!! Delete current and errored backup."
rm -rf "$MY_BACKUP_DIR_A"
exit 9
fi
fi

0 comments on commit 4f5466e

Please sign in to comment.