D
D
dmilkoff2022-03-09 11:17:26
bash
dmilkoff, 2022-03-09 11:17:26

How to automate the movement of files with conditions?

To optimize the space, you need to solve the problem of constantly moving files from 1 folder to a backup for a period (in case the author suddenly asks) for 3 months, followed by deletion.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2022-03-09
@ky0

Bash is endowed with all the necessary features in combination with find. Specify the question.

V
Viktor Taran, 2022-03-09
@shambler81

something like this ?
Create a backup folder
mkdir /tmp/backup

find /home/bitrix/ext_www/shop.ru/  -mtime  -30 -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)" -print0 | xargs -0 cp --parents --target-directory /tmp/backup

find- recursive search
/home/bitrix/ext_www/shop.ru/- where to look for
-mtime -30- values ​​that were created in the last 30 days can also take positive values.
-regexpnot necessarily just showed if you need only certain files,
-print 0you don’t really need it, but if you don’t just have files there, but a directory structure with attachments, then through the print we transfer to xargs in short, all directories will be created normally
xargx- explain for a long time
|- transfer to
cp --parents --target-directorycopies creating a
/tmp/backupdirectory directory itself .
Check it out, it should work
. As a result, you should get an identical directory structure necessary for those files that have been changed during this time.
All other directories and their contents are not copied.
such a backup can simply be uploaded over real files.
DELETE
find /tmp/backup -mtime +90 | xargs rm -f;
#deletes previous backups older than 90 days

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question