четверг, 18 апреля 2024 г.

Linux Bash rsync remote to remote with forwarding keys

We need it for loading files directly from one remote server to another one where we have SSH access.

SSH access from a Workstation -> Server1 -> rsync loading files -> Server2

ssh -v username@server1

find an identity SSH key for sure

ssh-add <the_key>

ssh -A username@server1

run with A option for allowing forwarding keys 

rsync -azP --exclude '.4y8-folder' --exclude 'file.tar.gz' pub/media/ username@server2:pub/media/

среда, 14 июня 2023 г.

Linux Bash remove old files more than 10 if exists

if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi 

to crontab

/bin/bash -c "if [ $(expr $(ls -1 /test/111 | wc -l | tr -d ' ')) -gt 10 ]; then rm $(ls -d -1 -At /test/111/* | tail -n $(expr $(ls -1 /test/111 | wc -l | tr -d ' ') - 10)) ; fi"

среда, 24 мая 2023 г.

Linux Bash rsync only specific a files list

Check rsync --help whether it supports --files-from= option 

lst content

./folder-source/1/1

./folder-source/2/2

...

cd to a folder where folder-source as a sub-folder (it's an explanation of period "." in rsync command)

rsync --files-from=/tmp/lst . /app/var/folder-sync

четверг, 6 апреля 2023 г.

Linux Bash find multiple conditions and move files

remove only *.dat and *.csv files older than 4 moths 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec rm '{}' ';'

or move the files, but please be aware if destination is wrong or some bad happens then you'll lose files 

find /path -type f -mtime +120 \( -name '*.dat' -or -name '*.csv' \) -exec mv '{}' /destination/ ';'

пятница, 11 ноября 2022 г.

Linux logrotate jira logs

 Jira has its own log rotate

However, it doesn't delete old files.

It can be done with crontab though.

#### remove old jira log files longer 180 days

30 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +180 -exec rm -rf {} \;

45 2 * * * /usr/bin/find /opt/atlassian/servicedesk/logs/ -maxdepth 1 -type f -mtime +6 -exec gzip -q {} \;