Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix variable missing word #4

Merged
merged 4 commits into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ sudo bash backup.sh
```
containerID:::user:::password:::database
```
### Minio backup requirment on servers

```
mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> <API-SIGNATURE>

```
for example

```
mc config host add minio http://192.168.1.51 BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 --api S3v4
```

and replace minio with minio_cluster_name

### Requirements

Expand All @@ -37,14 +50,17 @@ containerID:::user:::password:::database

- Added GitLab backup with gitlab-rake

**V1.1**

- Added multiple MariaDB/MySQL docker backup
**V1.3**
- Added Minio backup

**V1.0**
### Main Requirement

- Added MongoDB backup support
- tar
- gzip
- bzip2
- mc

### TODO

- [ ] Docker volume backup support
- [ ] rsync directory files ( backup public or huge files)
69 changes: 47 additions & 22 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ backup_files="/root/.bash_history /etc/passwd"
backup_dir_enable="no"
backup_directories="/etc /var/log /usr/local"

# GitLab backup
# Change to copy if the data changes while backing up
# Can be "copy" or "tar"
gitlab_backup="no"
gitlab_mode="tar"
gitlab_config="/etc/gitlab/gitlab.rb"
# backup sync directory to MinIO (Multi value)
backup_to_minio_enable="no"
minio_directories="/etc /var/log /usr/local"
minio_bucket=""
minio_cluster_name=""

# Copy to other media (Multi value)
external_copy="no"
external_storage="/mnt"

# Copy tar backup to MinIo
external_minio_copy="no"
external_minio_bucket=""
external_minio_cluster_name=""

# SCP to other server (Trusted servers for now)
scp_enable="no"
scp_server="1.2.3.4"
Expand Down Expand Up @@ -201,6 +205,27 @@ fi

sleep 1

# Backing up the directories to MinIo
if [ $backup_to_minio_enable = "yes" ]
if ! [ -x "$(command -v mc)" ]; then
echo 'Error: minio client (mc) is not installed.' >&2
exit 1
fi
then
echo -e "\n ${color}--- $date_now Backing up directories \n${nc}"
echo "$date_now Backing up directories" >> $log_file
for backup_dirs in $minio_directories
do
echo "--> $backup_dirs" | tee -a $log_file
dir_name=`echo $backup_dirs | awk -F'/' '{print $NF}'`
mc mirror --overwrite $backup_dirs ${minio_cluster_name}/${minio_bucket}/${dir_name}
done
echo
fi

sleep 1


# MySQL backup
if [ $mysql_backup = "yes" ]
then
Expand Down Expand Up @@ -294,22 +319,22 @@ sleep 1

if [ $docker_mysql_backup = "yes" ]
then
echo -e "\n ${color}--- $date_now Docker Mariadb/MySQL backup enabled, backing up: \n${nc}"
echo "$date_now Docker MySQL backup enabled, backing up" >> $log_file
for docker_mysql_container in $docker_mysql_containers
do
docker_mysql_container_id=`echo $ocker_mysql_container | awk -F":::" '{print $1}'`
docker_mysql_container_name=`docker ps --filter "id=$docker_mysql_container_id" | awk '{print $11}'`
docker_mysql_user=`echo $ocker_mysql_container | awk -F":::" '{print $2}'`
docker_mysql_pass=`echo $ocker_mysql_container | awk -F":::" '{print $3}'`
docker_mysql_database=`echo $ocker_mysql_container | awk -F":::" '{print $4}'`
docker exec $docker_mysql_container_id /usr/bin/mysqldump -u $docker_mysql_user --password=$docker_mysql_pass $docker_mysql_database | gzip -9 > $backup_path/Backup/$path_date/Docker_MySQL_${docker_mysql_container_name}_Dump_$path_date.sql.gz | tee -a $log_file
if [ $? -eq 0 ]
then
echo -e "\n ${color}--- $date_now Docker Mariadb/MySQL backup completed. \n${nc}"
echo "$date_now Docker Mariadb/MySQL backup completed" >> $log_file
fi
done
echo -e "\n ${color}--- $date_now Docker Mariadb/MySQL backup enabled, backing up: \n${nc}"
echo "$date_now Docker MySQL backup enabled, backing up" >> $log_file
for docker_mysql_container in $docker_mysql_containers
do
docker_mysql_container_id=`echo $docker_mysql_container | awk -F":::" '{print $1}'`
docker_mysql_container_name=`docker ps --filter "id=$docker_mysql_container_id" | awk '{print $11}'`
docker_mysql_user=`echo $docker_mysql_container | awk -F":::" '{print $2}'`
docker_mysql_pass=`echo $docker_mysql_container | awk -F":::" '{print $3}'`
docker_mysql_database=`echo $docker_mysql_container | awk -F":::" '{print $4}'`
docker exec $docker_mysql_container_id /usr/bin/mysqldump -u $docker_mysql_user --password=$docker_mysql_pass $docker_mysql_database | gzip -9 > $backup_path/Backup/$path_date/Docker_MySQL_${docker_mysql_container_name}_Dump_$path_date.sql.gz | tee -a $log_file
if [ $? -eq 0 ]
then
echo -e "\n ${color}--- $date_now Docker Mariadb/MySQL backup completed. \n${nc}"
echo "$date_now Backing up files" >> $log_file
fi
done
fi


Expand Down