-
Notifications
You must be signed in to change notification settings - Fork 11
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
How to backup or mirror elkar db? #39
Comments
From a remote server, to dump Elkarbackup MariaDB database running hidden (no exposed ports and running inside a specific Docker network) I do the following:
Here it is: #!/bin/bash
MYSQL_DB=elkarbackup
MYSQL_DOCKER_CONTAINER=mysql
MYSQL_PASSWORD=`cat $CURRENTDIR/mysql.txt`
#MYSQL_USER=elkarbackup # permission problem
MYSQL_USER=root
REPOSITORY=/opt/elkarbackup #volume on remote host server (not remote docker )
SERVER=192.168.1.1
SERVER_USER=root
SERVER_DOCKER_CONTAINER=elkar
SSH_PORT=22
SSH_OPTIONS="-o IdentityFile=/opt/elkarbackup/.ssh/id_rsa"
OUTPUTDIR=/srv/elkar-nuvem #dir for saving repo backup on server running this script
USED1=` df -h $OUTPUTDIR | awk 'NR==2 { print $3 }'`
USE1=` df -h $OUTPUTDIR | awk 'NR==2 { print $5 }'`
AVAILABLE1=`df -h $OUTPUTDIR | awk 'NR==2 { print $4 }'`
function show_filesystem_space {
USED2=` df -h $OUTPUTDIR | awk 'NR==2 { print $3 }'`
USE2=` df -h $OUTPUTDIR | awk 'NR==2 { print $5 }'`
AVAILABLE2=`df -h $OUTPUTDIR | awk 'NR==2 { print $4 }'`
say "
--------- INFO writing to $OUTPUTDIR ---------
Used disk space: BEFORE: $USED1 ($USE1) / AFTER: $USED2 ($USE2)
Available disk : BEFORE: $AVAILABLE1 / AFTER: $AVAILABLE2
"
}
function say {
theDATE=`date +'%d/%m/%y-%H:%M'`
echo "-----------------------------------"
echo "[MSG]: $theDATE => $1";
echo "-----------------------------------"
}
trap show_filesystem_space 0 1 2
echo "echoing variables..."
echo "------------------------------------------"
echo -e "MYSQL_DB = $MYSQL_DB"
echo -e "MYSQL_DOCKER_CONTAINER = $MYSQL_DOCKER_CONTAINER"
echo -e "MYSQL_PASSWORD = $MYSQL_PASSWORD"
echo -e "MYSQL_USER = $MYSQL_USER"
echo -e "REPOSITORY = $REPOSITORY"
echo -e "SERVER = $SERVER"
echo -e "SERVER_USER = $SERVER_USER"
echo -e "SERVER_DOCKER_CONTAINER = $SERVER_DOCKER_CONTAINER"
echo -e "SSH_PORT = $SSH_PORT"
echo -e "OUTPUTDIR = $OUTPUTDIR"
echo "------------------------------------------"
echo "Testing output dir $OUTPUTDIR"
if [ ! -d $OUTPUTDIR ]; then
echo "Creating output dir $OUTPUTDIR"
install -m 700 -d $OUTPUTDIR
fi
if [ $? -ne 0 ]
then
echo "[ERROR] creating output dir [$OUTPUTDIR]"
exit 1
fi
say "Backing up MySQL database from docker container to elkarbackup.sql..."
ssh -p $SSH_PORT $SSH_OPTIONS "$SERVER_USER@$SERVER" "docker exec -i $MYSQL_DOCKER_CONTAINER mysqldump -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB" > $OUTPUTDIR/elkarbackup.sql
if [ $? -ne 0 ]
then
echo "[ERROR] executing MySQL dump => exit status = $?"
exit 1
fi
chmod 600 $OUTPUTDIR/elkarbackup.sql
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking at the backup script to copy the repository, it connects to the elkar server using ssh, then does a mysqldump. How would you do this with docker? There is no ssh open on the docker containers, the client has ssh installed, but no mysql cmds, the db does not have ssh and the main container has mysql and rsync, but no ssh. Just looking for a suggestion on how you would do this. Thanks
The text was updated successfully, but these errors were encountered: