question

arunkumar-8707 avatar image
0 Votes"
arunkumar-8707 asked arunkumar-8707 answered

automate Zipping files on dailybasis

Hi Team

daily lot of log files are generating in some particular folder in Linux VM. i want to zip those files on date wise for example 15-20 log files are generating today that should be zipped to one file. likewise the files generating tomorrow should be zipped to one file.

please help me with the suitable command so that i can make it automate by adding that in crontab so that files should get zipped on date wise.

msc-operations-manager
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@arunkumar-8707,
As we are mainly responsible for Microsoft Teams running on Linux machine, your question related to Linux system is not supported by us. I will remove office-teams-linux-itpro tag for this thread. Thanks for your understanding.

0 Votes 0 ·
AlexZhu-MSFT avatar image
0 Votes"
AlexZhu-MSFT answered

Hi,

Here's a sample for your reference (you need to modify the command to cater for your real environment):

1) create a file with .sh suffix (linux shell script) and give execute permission for the file
143631-linux-command.png

2) edit the file
143600-linux-tar-command.png


3) edit crontab to add a line to run the file daily
for example, at 23:59 in each day, the shell script will run once (we can add more logic in the script file if requried)
143641-linux-crontab.png

Regards,

Alex
If the response is helpful, please click "Accept Answer" and upvote it.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

arunkumar-8707 avatar image
0 Votes"
arunkumar-8707 answered

Hi Alex

As per your answer all the files in the folder will get zipped. but i need only the files which are created on that particular day in that folder should get zipped and it should not zip all the files in that folder.

the log files which are generated today should get zip to one zipped file, the log files which are going to generate tomorrow should get zipped to other zipped file tomorrow and should happen like this.

Please help me with solution.

Regards
Arun

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexZhu-MSFT avatar image
0 Votes"
AlexZhu-MSFT answered AlexZhu-MSFT commented

Hi,

Try something like this (zipper.sh):

 #!/bin/bash
 touch -t `date +%m%d0000` /tmp/$$
 find . -type f -newer /tmp/$$ | xargs tar cvf /tmp/backup-"`date +"%d-%m-%Y"`".tar
 rm /tmp/$$

144744-linux-find-xargs-command.png

Regards,

Alex
If the response is helpful, please click "Accept Answer" and upvote it.



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

How's everything going? Have we settled this problem down? Or is there any other help that we can provide?

Regards,

Alex
If the response is helpful, please click "Accept Answer" and upvote it.

0 Votes 0 ·
arunkumar-8707 avatar image
0 Votes"
arunkumar-8707 answered

Hi Alex

i also need one more help regarding above issue. if i run the script above you mentioned it will delete all the files in the folder. but i want to delete only the files which are zipped, can you please help me with that.

Regards
Arun

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.