Last active
August 3, 2021 15:32
-
-
Save dpvpro/0e310f60a0453aaee53b790e4e824758 to your computer and use it in GitHub Desktop.
Backup Jenkins on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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