Skip to content

Instantly share code, notes, and snippets.

@kwonghung-YIP
Created December 14, 2020 09:36
Show Gist options
  • Save kwonghung-YIP/d6efcc2b0e70ce7dfce593223c5e3899 to your computer and use it in GitHub Desktop.
Save kwonghung-YIP/d6efcc2b0e70ce7dfce593223c5e3899 to your computer and use it in GitHub Desktop.
[docker-CLI] backup the jenkins_home volume for Jenkins service in docker swarm
#!/bin/bash
bkupdir="<your backup folder>/bkup_`date +%Y%m%d_%H%M%S`"
log="$bkupdir/backup.log"
mkdir -p $bkupdir
echo "backup folder : $bkupdir"
echo "Start time : `date`" >> $log
echo "backup folder : $bkupdir" >> $log
ctrId=`docker ps -q --filter "label=com.docker.swarm.service.name=<your jenkins service name>" --filter "status=running"`
docker run --rm -it \
--volumes-from $ctrId \
-v $bkupdir:/bkup \
ubuntu \
tar -cf /bkup/jenkins_home.tar -C /var/jenkins_home secrets
echo "End date : `date`" >> $log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment