Skip to content

Instantly share code, notes, and snippets.

@dpvpro
Last active August 3, 2021 15:32
Show Gist options
  • Save dpvpro/0e310f60a0453aaee53b790e4e824758 to your computer and use it in GitHub Desktop.
Save dpvpro/0e310f60a0453aaee53b790e4e824758 to your computer and use it in GitHub Desktop.
Backup Jenkins on Linux
#!/bin/bash
#set -x
COUNT_OLD_TAR=10
# example name backup_20170404_1553.tar.gz
TIME=$(date +%Y%m%d_%H%M%S)
FILENAME=backup_$TIME.tar.gz
SRCDIR=/var/lib/jenkins
#DESTDIR=~/jenkins_backup
#cd $DESTDIR
tar -cpzf $FILENAME $SRCDIR
# delete more NUMBER_LOG_FILES files
TAR_FILES=$(ls -txr1 *.tar.gz)
NUMBER_TAR_FILES=$(echo "$TAR_FILES" | wc -l)
if [ $NUMBER_TAR_FILES -gt $COUNT_OLD_TAR ]; then
rm $(echo "$TAR_FILES" | head -n -$COUNT_OLD_TAR)
logger "удаление старых tar фалов"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment