how to convert vmdk image to hda.qcow2 - window

I am trying to convert vmdk formate image to hda.qcow2 formate through this command:
qemu-img convert -f vmdk -O qcow2 server\server2016.vmdk hda.qcow2
but it show the following error
qemu-img : The term 'qemu-img' is not recognized as the name of a cmdlet,
function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ qemu-img convert -f vmdk -O qcow2 server2016.vmdk server2016.qcow2
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (qemu-img:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

I do this two-stage conversion (vmdk->raw->qcow2) in bash using qemu-img QEMU utility (in Debian qemu-utils package)
echo "Converting multiple VMDK files in $PWD into QCOW2..."
rm -f tmpImage.raw
for i in *.vmdk; do
echo "Converting $i ..."
qemu-img convert -f vmdk "$i" -O raw "$i.raw"
cat "$i".raw >> tmpImage.raw
done
echo "Creating finalImage.qcow2..."
qemu-img convert tmpImage.raw finalImage.qcow2
rm tmpImage.raw
The only real question is whether we want to append the unsequenced "$i.vmdk" file to the end of its final raw image before converting, but it seems to work best this way.

Related

Bash Script Using API for Online Image Vectorizing

I am a user of vectorizer.io services, but I now need to batch convert and that requires a script utilizing their API. Their customer service sent me a script written in ChatGPT that users have put together, but it isn't working for me (API credentials were removed for posting). I receive this error:
curl: (26) Failed to open/read local data from file/application
Script:
#!/bin/bash
# Set the api credits code: found in menu / "email address button" / "Api Settings" (enable 'pay for additional credits' if you want to use more than the included 100 api calls)
API_CREDITS_CODE=""
# Set the directory to search for GIF files
DIRECTORY="/Users/User/Desktop/folderofimages"
# Find all GIF files in the specified directory
for file in $(find "$DIRECTORY" -name "*.gif"); do
# Extract the filename without the file extension
filename="${file%.*}"
# Call the curl command, replacing the X-CREDITS-CODE header with the api credits key and the input and output filenames
curl --http1.1 -H "Expect:" --header "X-CREDITS-CODE: $API_CREDITS_CODE" "https://api.vectorizer.io/v4.0/vectorize" -F "image=#$file" -F "format=svg" -F "colors=0" -F "model=auto" -F "algorithm=auto" -F "details=auto" -F "antialiasing=off" -F "minarea=5" -F "colormergefactor=5" -F "unit=auto" -F "width=0" -F "height=0" -F "roundness=default" -F "palette=" -vvv -o "${filename}.svg"
done
It would also be ideal if the script were to find and use images of all formats, not just GIF. That is not a necessity though.

How to use curl get image right filename and extension

My links just like below
https://cdn.sspai.com/2022/06/22/article/a88df95f3401d5b6c9d716bf31eeef33?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1
If I use chrome to open this like and cmd + s
I will get the right filename and right extension png.
But if I use bash below, then it will no extension:
curl -J -O https://cdn.sspai.com/2022/06/22/article/a88df95f3401d5b6c9d716bf31eeef33?imageView2/2/w/1120/q/90/interlace/1/ignore-error/1
I just want to download image with right filename and extension.
a88df95f3401d5b6c9d716bf31eeef33.png
Same error include different image links below:
https://cdn.sspai.com/article/fa848601-4cdf-38b0-b020-7afd6efc4a7e.jpg?imageMogr2/auto-orient/quality/95/thumbnail/!800x400r/gravity/Center/crop/800x400/interlace/1
You can get the name from the URL itself.
url="YOUR-URL"
file="`echo "${url}" | sed 's|\?.*|.jpg|' | xargs basename`"
curl -o "${file}.tmp" "${url}"
mv "${file}.tmp" "${file}"
Hope it helps

How to restore backup postgres database on windows machine

I have tried on terminal:
psql -d test < .\backup_database.sql
At line:1 char:14
+ psql -d test < .\backup_database.sql
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
pg_dump command worked seamlessly on terminal.
So where do i run psql command.
Tried on dbshell-Not working, Manually adding on pgadmin 4 gives pg_restore: error: input file appears to be a text format dump. Please use psql.
Don't use redirection on Windows, use the -f parameter to pass the file to be run:
psql -d test -f backup_database.sql

Creating a loop with curl -F argument

I have this bash script code:
#!/bin/bash
FILES=/home/user/Downloads/asd/
for f in $FILES
do
curl -F dir="#/home/user/Downloads/asd;$f" -F Match=3 -F "Name=DrKla" \
-F countNo=1 -F outputFormat=json "http://somelink.com"
done
Inside the asd folder there are 6 files and I want them to be uploaded 1 by 1 with this code as an argument of -F "dir=#...."
When I run my code I get the error:
Warning: skip unknown form field: /home/user/Downloads/asd/
curl: (43) A libcurl function was given a bad argument
Here is a working version of the code for a single file:
curl -F dir="#/home/user/Downloads/asd/count.txt" -F Match=3 -F "Name=DrKla" \
-F countNo=1 -F outputFormat=json "http://somelink.com"
So I want to have all the files in asd folder to be read and uploaded like this. I don't see what's wrong with my do loop.
The issues appear to be that you only give a path, not a reference to all files in the path * and there is a strange semi-colon ; in your path:
#!/bin/bash
FILES=/home/user/Downloads/asd/*
for f in $FILES
do
curl -F dir="#$f" -F Match=3 -F "Name=DrKla" \
-F countNo=1 -F outputFormat=json "http://somelink.com"
done
I'm not sure what the # is for or if it is needed, but $f should already contain the path.

Content-Disposition in dropbox

is there a way to rename a file while downloading from dropbox without changing the filename itself :
for example :
dropbox link : https://www.dropbox.com/s/uex431ou02h2m2b/300x50.gif?dl=1
and get file downloaded : NewNameImage.gif instead of 300x50.gif
Content-Disposition header didn't work for me .
any ideas how to do that ?
If you're downloading the file locally you should either be able to control the name given to the local file, or be able to rename it after the fact. For example, using curl, -JO downloads the file using the remote name specified in the Content-Disposition header, while -o lets you specify a name:
$ curl -L -JO "https://www.dropbox.com/s/uex431ou02h2m2b/300x50.gif?dl=1"
...
curl: Saved to filename '300x50.gif'
$ ls
300x50.gif
$ rm 300x50.gif
$ curl -L -o "NewNameImage.gif" "https://www.dropbox.com/s/uex431ou02h2m2b/300x50.gif?dl=1"
...
$ ls
NewNameImage.gif
Alternatively, renaming it after the fact:
$ curl -L -JO "https://www.dropbox.com/s/uex431ou02h2m2b/300x50.gif?dl=1"
...
curl: Saved to filename '300x50.gif'
$ ls
300x50.gif
$ mv 300x50.gif "NewNameImage.gif"
$ ls
NewNameImage.gif

Resources