Created 09-09-2024 03:25 AM
Using NiFi, I am processing a file. Once processing is done, I want to shift it to an archive folder. I want it to keep only say 30 days files and older files to be deleted. How to do. One more question is how to have timestamp name appended to file name. Like if file name is file1.txt then how to have it renamed like file1_09_09_2024_15_54.txt where we have 09_09_2024 as date and 15_54 as time(hour and mins)
Created 09-09-2024 06:08 AM
@AlokKumar
You have multiple questions here, let me address them separately:
${filename:substringBeforeLast('.')}_${now():format('MM_dd_yyyy_hh_mm')}.${filename:substringAfterLast('.')}
Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt
Created 09-09-2024 06:08 AM
@AlokKumar
You have multiple questions here, let me address them separately:
${filename:substringBeforeLast('.')}_${now():format('MM_dd_yyyy_hh_mm')}.${filename:substringAfterLast('.')}
Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt
Created 09-09-2024 07:19 AM
Hi @MattWho file naming part worked properly. Thanks
Could you please elaborare on the purging part where I want older files(older than 30 days) to be deleted.
Created 09-09-2024 09:34 AM
@AlokKumar
The idea is that after renaming your FlowFile, you use the putFile processor to write that file to your archive directories on each of the NiFi instances. That ends that dataflow.
You then start a new dataflow that consists of only the GetFile processor with its success relationship terminated and the minimum File Age property set to "30 days". Start this processor and it will continuously check the target archive directory for any files where the last modified timestamp has exceeded 30 days. Those files older then 30 days will be consumed and removed from archive assuming property "Keep Source File" is set to "false". Since the success "relationship" is set to auto-terminate, The FlowFile produced is terminated.
Please help our community thrive. If you found any of the suggestions/solutions provided helped you with solving your issue or answering your question, please take a moment to login and click "Accept as Solution" on one or more of them that helped.
Thank you,
Matt
Created 09-09-2024 11:47 PM
ok thank you