Background:
I have a Jenkins task that is executing and before running i want to take a copy of a folder and move it to another directory which does not exist and is a dynamic timestamp.
For the purposes of this argument i am not able to create variables to store anything, it must be accomplished without them. I have seen this other question on stackoverflow here, and this seems to confirm the approach i am going for.
Question:
What is the best way to achieve this for Linux/Unix?
I have an idea below but i want to check if this is the best approach or not. It starts by making the directory mkdir -p
with the location of the directory /tmp/backup/myapp/
and the date timestamp as the final folder name $(date +%Y%m%d%H%M%S)
, it then calls a recursive copy cp -r
and provides the source directory to be copied /var/www/html/myapp
and then passes in the original location url as the destination $_
Suggested Answer
mkdir -p /tmp/backup/myapp/$(date +%Y%m%d%H%M%S) && cp -r /var/www/html/myapp $_