33

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

Downloading to the current folder like this works:

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

But when I tried adding a folders path to 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 be saved and downloaded like this:

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

Where the folder nov-1-2016 is created dynamically when the cron is run, and the filename is the timestamp when the bkup was run.

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 1
    I'm guessing that `/db-bkups/` does not exsists? Like any other tool, is given path does not exists, you'll get an error. Try with `--create-dirs` argument like said downthere, or just specify path that exists. You can create `db-bkups` dir and it should work. – Aleksandar Nov 11 '16 at 04:43

1 Answers1

79

You could try using the --create-dirs argument which was added in curl 7.10.3:

Here is an example that will create the directory hierarchy, (if it doesn't already exist), and will name the subdirectory you require renamed with the output of the datecommand:

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

The result is a file stored in a directory like so /db-bkups/Nov-04-2016/timestamp-db.dump.

Cristian Ciupitu
  • 20,270
  • 7
  • 50
  • 76
Zlemini
  • 4,827
  • 2
  • 21
  • 23
  • Tried this with cygwin `curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL` with no joy. Luckily I am able to create the parent directories, so there is a work around ... it is a pain though!! – Bill Naylor Oct 08 '19 at 15:43
  • 2
    Works with the current [official native Windows builds of curl](https://curl.se/windows/). – Anaksunaman Jun 20 '21 at 01:15
  • for ftp or sftp connections the key is `--ftp-create-dirs`. For example `curl -T path/to/local_file.txt ftp://1.2.3.4/my_new_folder/ --ftp-create-dirs -u username:password` – Eugene Kaurov Jan 10 '23 at 22:00