How to upload a file to a newly created directory with curl on OS X?

I am trying to upload my Heroku backups to a folder.

Download to the current folder, how it works:

curl -o latest.dump `heroku pg:backups public-url`

But when I tried to add the path foldersto latest.dump, it looks like this:

$ curl -o /db-bkups/latest.dump `heroku pg:backups public-url`
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 44318    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0Warning: Failed to create the file 
Warning: /db-bkups/latest.dump: No such file 
Warning: or directory
 36 44318   36 16384    0     0   9626      0  0:00:04  0:00:01  0:00:03  9626
curl: (23) Failed writing body (0 != 16384)

Ideally, I would like it to be saved and loaded as follows:

/db-bkups/nov-1-2016/timestamp-db.dump

If the folder nov-1-2016is created dynamically when cron starts, and the file name is the timestamp when bkup starts.

+9
source share
1 answer

You can try using the argument --create-dirsthat was added in curl 7.10.3 :

, ( ) , date:

curl -o /db-bkups/$(date +"%b-%d-%Y")/timestamp-db.dump --create-dirs http://www.w3schools.com/xml/simple.xml

, , /db-bkups/Nov-04-2016/timestamp-db.dump.

+15

Source: https://habr.com/ru/post/1659554/


All Articles