2

I want to create the backup of the Wordpress website in a directory example.com. The output file should be in the following format:

YmDHM_example.com.zip

Using the current date and time, it would be: 202003211045_example.com.zip.

So far I got to this point:

$ zip -r "$(date +"%Y%m%d%H%M")_example.com.zip" example.com

But would like the example.com part to be also created "dynamically". I saw this answer, but it doesn't mention how to include the date in the output file.

How can I do it?

Amade
  • 175
  • 2
  • 7

1 Answers1

4

Using find to filter and format output for zip command:

$ find -maxdepth 1 -type d -name 'example.com' \
  -printf %f\\0 | xargs -0 -I {} zip -r $(date -d now +%Y%m%d%H%M)_{}.zip {}