I am getting the databases from mysql and my database name is username_something. I am getting the username and then puting the respective backups in corresponding folders like

tar bala bla  /backups/sql/username/username_something.tar.sql.gz

The problem is system worrks if i have the folder username already there but for new databases if get the error like unknown file path.

How can i do that if username folder is not there it should be created


You can use mkdir before the tar command to create the directory. If multiple dirs in the path may be missing, you can use the -p flag. Using -p will also suppress the error if the directory already exists.

mkdir -p /backups/sql/username && tar ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.