databricks - no response when executing command in terminal 'export DATABRICKS_CONFIG_FILE="dbfs:/FileStore/tables/partition.csv' - azure

I am trying to export the csv file by following this guide https://docs.databricks.com/dev-tools/cli/index.html , but there's no response when executing below command, it looks like exist the command directly without saying exporting is successfully or failed.
I have finished install the cli and setup authentication by entering a host and token in mac terminal by following the guide as well.
export DATABRICKS_CONFIG_FILE="dbfs:/FileStore/tables/partition.csv"
please refer to this screenshot:
At first, I write the dataframe into file system by below code
df.coalesce(1).write.mode("overwrite").csv("dbfs:/FileStore/tables/partition.csv")
how could i successfully export the file from databricks and where does it stored locally?
screenShot:

Yes, you can copy to your local machine or move to another destination as needed
Configure azure CLI with azure databricks:
Please follow this steps:
pip install databricks-cli
Use databricks configure --token command
Mention Azure databricks host name: https://adb-xxxxx.azuredatabricks.net/
Past your Personal Access Token.
Now all set to export the CSV file and store it in a destination location.
databricks fs cp dbfs:/FileStore/tables/partition.csv dbfs:/destination/your_folder/file.csv
databricks fs cp C:/folder/file.csv dbfs:/FileStore/folder
Or
If you have a lot of CSV files placed in a folder .you prefer to export the entire folder rather than individual files.
Use -r to select your folder instead of the individual file.
databricks fs cp -r dbfs:/<folder> destination/folder
Alternative approach in python:
You can use directly dbutils.fs.cp("dbfs:/FileStore/gender_submission.csv","destination/folder")

Related

Execute shell script for database backup

I have a ReactJS-neo4j application, deployed on a cloud server. Currently, i create backups of my databases manually.
Now I want to automate this process. I want to automatically execute the above query every day
Can anyone tell me how to automate the above process ?
You need to change your neo4j configuration file found in <HOME_neo4j>/conf/neo4j.conf as below. The location of the file is different if you are not using Linux server, like Debian.
apoc.export.file.enabled=true
apoc.import.file.use_neo4j_config=false
The 2nd line will enable you to save the json file from default folder "import" to any folder you want.
Then open a terminal (or ssh) that connects to your cloud server. Go to <HOME_neo4j> directory where cypher-shell is installed. Copy and run this one liner script below.
echo "CALL apoc.export.json.all(\"/home/backups/deploymentName/backup_mydeployment.json\", { useTypes: true } )" | bin/cypher-shell -u neo4j -p <awesome_psw> --format plain
This will save the json file in /home/backups/deploymentName just like what you do in your neo4j browser.
I will leave it up to you on 1) how to add the timestamp YYMMDD0000_ in the filename via linux command and 2) schedule the job every midnight via crontab. Goodluck!

How to download a folder in a private container of Azure Storage

I can download all files inside a folder in my storage, if the container is set as annonymous access, using azcopy and the following command:
AzCopy cp https://.blob.core.windows.net/files/modules/ C:\Users\AppData\Roaming\modules --recursive --log-level NONE & azcopy jobs clean
But when I set the container back to private access, it says:
failed to perform copy command due to error: Login Credentials missing. No SAS token or OAuth token is present and the resource is not public
INFO: Removed 0 files.
I know how to generate the SAS for a unique specific file but in this case that I'm downloading a folder, how to proceed?
Please use this command:
AzCopy cp 'https://<your-storage-name>.blob.core.windows.net/container/<folder>?<your-sas-token>' 'C:\Users\AppData\Roaming\modules' --recursive
You can generate SAS token there:

Trying to use azcopy for copying file from storage account

Uploaded a .sh file into storage account and trying to get that into rhel vm. I have azcopy version 10.6.1. Command i am using azcopy copy ā€¯https://.blob.core.windows.net/container/test.sh>[SAS token]" . When i run this, it is moving to next line and giving this ">" output. Tried to do in many ways but no luck.
How can we troubleshoot this issue?
The syntax to use "azcopy copy" command is
azcopy copy [source] [destination] [flags]
To download a single file by using a SAS token:
azcopy cp "https://[account].blob.core.windows.net/[container]/[path/to/blob]?[SAS]" "/path/to/file.txt"
To download a single file by using a SAS token and then piping the output to a file (block blobs only):
azcopy cp "https://[account].blob.core.windows.net/[container]/[path/to/blob]?[SAS]" > "/path/to/file.txt"
This is the source of above information.
Related references:
Download blobs from Azure Blob storage by using AzCopy v10
Troubleshoot Azcopy related issues

Download the files in azure using azcopy

I am trying to download the files from the blod container in azure...But its showing Error: Unknowncommand
Cmd:
AzCopy https://forecast.blob.core.windows.net/test C:\Users\Shwettha\Downloads\azcopyfiles /sourceKey:sp=rl&st=2020-07-17T12:17:25Z&se=2020-12-31T21:30:00Z&sv=2019-10-10&sr=c&sig=z9b0X4vT6DGy6zOGNffM5FVaK5jNGOTeFFWD /S /V:C:\temp\logs\azcopy.log
error:
Error: unknown command "https://forecast.blob.core.windows.net/test" for "azcopy"
I also tried
azcopy cp "https://forecast.blob.core.windows.net/test/apollo?si=Utopus&sv=2019-12-12&sr=c&sig=qHv1ojyG2hrjrq7ZQ%2BMAVZhkpCwrXs1" "utopus/apollo/forecast/dayahead" --recursive
Error: is not recognized as an internal or external command,
operable program or batch file.
Can anyone pls help me...to downlaod or list the files in the blob.
iam new to azcopy
Have tried below command
azcopy cp "https://forecast.blob.core.windows.net/test/apollo?si=Utopus&sv=2019-12-12&sr=c&sig=qHv1ojyG2BMAVZhkpCwrXsD" "c:/Users/Shwettha/Downloads/azcopyfiles" --recursive
It seems that you're trying to copy the contents of directory to local.
Here's something you need to check:
1.the version of your azcopy
2.Open your cmd in your computer, and navigate to the location where the azcopy.exe is.
3.the sastoken you're using, please follow the screenshot below to generate the sastoken(In azure portal):
4.suppose you have a blob container named test8, and the container has a directory named ccc. now if you want to download all the blobs inside the directory ccc, please use the command below:
azcopy cp "https://yy1.blob.core.windows.net/test8/ccc?your_sastoken" "d:\bbb" --recursive
Here is the screenshot:

Azcopy: Copying files to an Azure Fileshare using Azcopy 10

I'm trying to copy files to and from an Azure Fileshare using AZCopy v10. I have had this successfully working using v8.1 but I keep getting errors using v10.
From the command line I'm using this to copy a file from the local drive to the fileshare;
c:\Temp\azcopy.exe copy "c:\temp\sample.txt" "https://myfiles.file.core.windows.net/dbfiles/sample.txt?SASKeyText"
This generates the error message;
failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL
I have tried adding a directory to the fileshare and adding that to the command string but I get the same error.
If I reverse the copy from the fileshare to the local drive I get the error;
failed to perform copy command due to error: account copies are an inherently recursive operation, and thus --recursive is required
I have followed the guide at https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-files but haven't been able to see what's wrong.
Thanks in advance for any help.
The error here was with the SAS token and not the form of the command.
I suppose this should be marked up amongst examples of unhelpful error messages.
Thanks to everyone who took the time to have a look.
I had this same issue when trying to do a copy from my local machine to Azure Blob storage.
This was the command I was running:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web" --recursive
But I got the error below:
failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL
Here's how I solved it:
I was missing the ?[SAS] argument at the end of the Blob storage location. So instead of this:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web" --recursive
I had this:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web?[SAS]" --recursive
Note:
The format is azcopy copy "/path/to/dir" "https://[account].blob.core.windows.net/[container]/[path/to/directory]?[SAS]" --recursive. You only need to modify the "/path/to/dir", [account] and [container]/[path/to/directory]. Every other thing remains the way they are.
Specify the source-destination routing using the --from-to=LocalBlob (if you're copying from local to blob storage) argument to be explicit about the copy operation.
My actual Blob storage location is https://myapptest.blob.core.windows.net/$24web but I used https://myapptest.blob.core.windows.net/%24web, since $ will throw some error when used, so %24 was used.
That's all.
I hope this helps
Here is a sample azcopy script which worked for me
az storage azcopy blob upload
-c'https://$AZURE_STORAGE_ACCOUNT_NAME.blob.core.windows.net/\\\$web' \
--account-name $AZURE_STORAGE_ACCOUNT_NAME \
-s "build/*" \
--account-key $AZURE_STORAGE_ACCOUNT_ACCESS_KEY \
--recursive
If you get this error while trying to copy to $web container:
"failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL"
Per a solution listed here, we need to add an escape character (\) before $web. Following command (to copy all files and subfolders to web container) worked for me:
azcopy copy "<local_folder>/*" "https://******.blob.core.windows.net/\$web/?<SAS token>" --recursive
Without the escape character, the following command fails with the above error.
azcopy copy "<local_folder>/*" "https://******.blob.core.windows.net/$web/?<SAS token>" --recursive

Resources