Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

migrated from stackoverflow.com Nov 8 '10 at 11:22

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment
mkdir -p /backups/sql/username && tar ...
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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