1cbackup: различия между версиями
Перейти к навигации
Перейти к поиску
Vovan (обсуждение | вклад) (Новая страница: «mkdir ~/1c_backup cat ~/1c_backup/backup.sh #!/bin/bash export LANG=ru_RU.UTF-8 dest="$(dirname $0)/backup__$(date +%Y-%m-%d-%H-%M-%S).dt" cmd="/opt/1cv8t/x86_6…») |
Vovan (обсуждение | вклад) |
||
(не показаны 4 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
− | mkdir ~/1c_backup | + | mkdir ~/1c_backup |
− | cat ~/1c_backup/backup.sh | + | <pre> |
+ | cat << 'EOF' > ~/1c_backup/backup.sh | ||
#!/bin/bash | #!/bin/bash | ||
export LANG=ru_RU.UTF-8 | export LANG=ru_RU.UTF-8 | ||
Строка 12: | Строка 13: | ||
function backup(){ | function backup(){ | ||
− | + | DISPLAY=:0 ${cmd} config /N "Администратор" /F "/home/student/Документы/InfoBase" /D "test" /DumpIB ${dest} | |
− | |||
− | |||
− | DISPLAY=:0 ${cmd} config /N " | ||
} | } | ||
Строка 45: | Строка 43: | ||
backup | backup | ||
rotate_backups | rotate_backups | ||
+ | EOF | ||
+ | </pre> | ||
+ | |||
+ | chmod +x ~/1c_backup/backup.sh | ||
+ | |||
+ | EDITOR=nano crontab -e | ||
+ | |||
+ | crontab -l | ||
+ | |||
+ | <pre> | ||
+ | #minute (0-59), | ||
+ | #| hour (0-23), | ||
+ | #| | day of the month (1-31), | ||
+ | #| | | month of the year (1-12), | ||
+ | #| | | | day of the week (0-6 with 0=Sunday). | ||
+ | #| | | | | commands | ||
+ | */1 * * * * ~/1c_backup/backup.sh | ||
+ | </pre> | ||
+ | |||
+ | watch "ls ~/1c_backup/" |
Текущая версия на 12:11, 11 июня 2024
mkdir ~/1c_backup
cat << 'EOF' > ~/1c_backup/backup.sh #!/bin/bash export LANG=ru_RU.UTF-8 dest="$(dirname $0)/backup__$(date +%Y-%m-%d-%H-%M-%S).dt" cmd="/opt/1cv8t/x86_64/8.3.23.1865/1cv8t" keep="3" # minutes current_unixtime=`date +%s` test_unixtime=$(($current_unixtime-$keep*60)) function backup(){ DISPLAY=:0 ${cmd} config /N "Администратор" /F "/home/student/Документы/InfoBase" /D "test" /DumpIB ${dest} } function rotate_backups(){ filenames_cmd="$(dirname $0)/*.dt" for f in $(/bin/ls $filenames_cmd); do datetime_from_file=`echo ${f} | awk -F '__' {'print $2'} | awk -F '.' {'print $1'}` #2023-12-24-22-01-02 Y=`echo ${datetime_from_file} | awk -F '-' {'print $1'}` M=`echo ${datetime_from_file} | awk -F '-' {'print $2'}` D=`echo ${datetime_from_file} | awk -F '-' {'print $3'}` h=`echo ${datetime_from_file} | awk -F '-' {'print $4'}` m=`echo ${datetime_from_file} | awk -F '-' {'print $5'}` s=`echo ${datetime_from_file} | awk -F '-' {'print $6'}` unixtime_from_file=`date +%s --date="${Y}-${M}-${D} ${h}:${m}:${s}"` if [[ $unixtime_from_file -lt $test_unixtime ]]; then echo "delete file: ${f}" /bin/rm ${f} else echo "keep file: ${f}" fi done } backup rotate_backups EOF
chmod +x ~/1c_backup/backup.sh
EDITOR=nano crontab -e
crontab -l
#minute (0-59), #| hour (0-23), #| | day of the month (1-31), #| | | month of the year (1-12), #| | | | day of the week (0-6 with 0=Sunday). #| | | | | commands */1 * * * * ~/1c_backup/backup.sh
watch "ls ~/1c_backup/"