-
Notifications
You must be signed in to change notification settings - Fork 5
/
1c_reg_log_compress.sh
executable file
·51 lines (40 loc) · 1.87 KB
/
1c_reg_log_compress.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
#
# Эксплуатация 1С Предприятия 8.3: Сжатие и удаление файлов ЖР
#
# (c) 2020, Алексей Ю. Федотов
#
# Email: [email protected]
#
# ======================================================
# ВНИМАНИЕ: Использовать только для ЖР в старом формате
# ======================================================
#
# Find 1C Enterprise 8 service start script
INIT_SCRIPT=$(ls /etc/init.d/srv1cv8*)
ARCHIVE_PERIOD=$(date +%Y%m%d --date='2 week ago')
REMOVE_PERIOD=$(date +%Y%m%d --date='2 month ago')
# Use system 1C Enterprise settings
source ${INIT_SCRIPT} > /dev/null
[[ -d /etc/sysconfig ]] && source /etc/sysconfig/${INIT_SCRIPT##*/}
# Get real cluster work directory
[[ -z ${SRV1CV8_DATA} ]] && SRV1CV8_DATA="$(grep ${SRV1CV8_USER} /etc/passwd | cut -f6 -d:)/.1cv8/1C/1cv8"
# Get real work dir
[[ -f ${SRV1CV8_DATA}/location.cfg ]] && SRV1CV8_DATA=$(cut -f2 -d'=' ${SRV1CV8_DATA}/location.cfg )
# TODO: Add -mtime parameter for restrict find result
FILES_TO_COMPRESS=$(find ${SRV1CV8_DATA} -name '*.lgp' | sort)
DEL_FILES=0; ARCH_FILES=0
for CURRENT_FILE in ${FILES_TO_COMPRESS}; do
if [[ ${CURRENT_FILE##*/} < ${REMOVE_PERIOD} ]]; then
rm -f ${CURRENT_FILE} && (( DEL_FILES+=1 ))
elif [[ ${CURRENT_FILE##*/} < ${ARCHIVE_PERIOD} ]]; then
bzip2 ${CURRENT_FILE} && (( ARCH_FILES+=1 ))
fi
done
# TODO: Add -mtime parameter for restrict find result
FILES_TO_REMOVE=$(find ${SRV1CV8_DATA} -name '*.bz2' | sort)
for CURRENT_FILE in ${FILES_TO_REMOVE}; do
[[ ${CURRENT_FILE##*/} < ${REMOVE_PERIOD} ]] && rm -f ${CURRENT_FILE} && (( DEL_FILES+=1 ))
done
[[ ${ARCH_FILES} -gt 0 ]] && echo "Количество сжатых файлов ЖР: ${ARCH_FILES}"
[[ ${DEL_FILES} -gt 0 ]] && echo "Количество удаленных файлов ЖР: ${DEL_FILES}"