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.
To download a file with Curl, use the --output or -o command-line option. This option allows you to save the downloaded file to a local drive under the specified name. If you want the uploaded file to be saved under the same name as in the URL, use the --remote-name or -O command line option.
How to download a file with curl command. The basic syntax: Grab file with curl run: $ curl https://your-domain/file.pdf. Get file using ftp or sftp protocol: $ curl ftp://ftp-your-domain-name/file.tar.gz.
To download multiple files at the same time, use –O followed by the URL to the file that you wish to download. If you curl without any options except for the URL, the content of the URL (whether it's a webpage, or a binary file, such as an image or a zip file) will be printed out to screen.
Consequentially, the file will be saved in the current working directory. If you want the file saved in a different directory, make sure you change current working directory before you invoke curl with the -O, --remote-name flag!
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 date
command:
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With