Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: mysqldump

  1. #1
    Join Date
    Feb 2019
    Beans
    12

    mysqldump

    good morning,
    with mysql I have to manage several databases and I want to do the scheduled backup with crontab
    Using the backup command for all databases:
    Code:
    mysqldump -u root -p [password_user_root] --all-databases | gzip> /var/www/example.com/backupsql/wp_`date + \% F _ \% T`.sql.gz
    I have no problems.
    But if instead I wanted to backup the single database:
    Code:
    mysqldump -u root -p [password_user_root] --databases wp | gzip> /var/www/example.com/backupsql/wp_`date + \% F _ \% T`.sql.gz
    I get the error

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: mysqldump

    https://ubuntuforums.org/showthread....7#post13802377
    is how I do it. Notice that the password is read from a file, not in the command options which any userid can see in the process table. Also, that the full path to any programs are spelled out. Never trust the PATH in any script, especially one started from cron.

    There a many other solutions too.

  3. #3
    Join Date
    Sep 2011
    Location
    Behind you!
    Beans
    1,690
    Distro
    Ubuntu 20.04 Focal Fossa

    Re: mysqldump

    Just want to +1 what TheFu said about placing the password in clear view as part of the command...which is exposed in your command history and the process list. You can also store the password in my.cnf which will process the credentials automatically.

    When scheduling in crontab, always specify the full path to everything (including the programs) and never use relative paths...unless you are explicitly specifying the path environment at the beginning.

    You are probably just showing us the crux of the problem and what you are doing is more complicated than just scheduling that one command but in case it is not, I'd recommend calling a script from crontab and placing your commands inside that and including error-catching, logging and notifications so the backups can be more robust and let you know if things go sideways or maybe even self-correct if you plan ahead for certain scenarios (low disk space, write permissions, unmounted targets, etc.)

    LHammonds

  4. #4
    Join Date
    Feb 2019
    Beans
    12

    Re: mysqldump

    Quote Originally Posted by LHammonds View Post

    You are probably just showing us the crux of the problem and what you are doing is more complicated than just scheduling that one command ...

    LHammonds
    Exact
    Leaving aside security, I would like to understand why copying all the databases I have no problem, but if with the same command I copied only a single database, I get an error
    So I ask you, what's wrong with mysqldump for single database?

    I thank you for the precious support you are giving me!!!

  5. #5
    Join Date
    Sep 2014
    Location
    United States
    Beans
    362
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: mysqldump

    Nothing is wrong for mysqldump single database. I do this routinely. Without the error message however, I cannot debug.
    I'm the Sisyphus in security engineering.

    Read about 14.04 ESM and Puppet inside of Docker Containers.

  6. #6
    Join Date
    Feb 2019
    Beans
    12

    Re: mysqldump

    Quote Originally Posted by EuclideanCoffee View Post
    Nothing is wrong for mysqldump single database. I do this routinely. Without the error message however, I cannot debug.
    I try to explain myself better:
    With the option for single databases I received the error:
    Code:
    root@linux:/home/paolo# mysqldump -u root -p [password_user_root] --databases wp | gzip > /var/www/example.com/backupsql/wp_`date +\%F_\%T`.sql.gz
    Enter password:
    mysqldump: Got error: 1049: Unknown database '[password_user_root]' when selecting the database


    With the option for all databases the password is not required and the dump is performed correctly:
    Code:
    root@linux:/home/paolo# mysqldump -u root -p [password_user_root] --all-databases | gzip > /var/www/example.com/backupsql/wp_`date +\%F_\%T`.sql.gz
    root@linux:/home/paolo#

  7. #7
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: mysqldump

    I've never used the "--databases" switch, though I usually prefer to use --all-databases. Try

    Code:
    mysqldump -u root -p [password_user_root] wp | gzip> /var/www/example.com/backupsql/wp_`date + \% F _ \% T`.sql.gz
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  8. #8
    Join Date
    Feb 2019
    Beans
    12

    Re: mysqldump

    Using the --all-databases option, in case you want to restore a single db, how should I operate ?

  9. #9
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: mysqldump

    Quote Originally Posted by paweltech View Post
    I try to explain myself better:
    With the option for single databases I received the error:
    Code:
    root@linux:/home/paolo# mysqldump -u root -p [password_user_root] --databases wp | gzip > /var/www/example.com/backupsql/wp_`date +\%F_\%T`.sql.gz
    Enter password:
    mysqldump: Got error: 1049: Unknown database '[password_user_root]' when selecting the database


    With the option for all databases the password is not required and the dump is performed correctly:
    Code:
    root@linux:/home/paolo# mysqldump -u root -p [password_user_root] --all-databases | gzip > /var/www/example.com/backupsql/wp_`date +\%F_\%T`.sql.gz
    root@linux:/home/paolo#
    The correct syntax is "-p[password_user_root]" without a space. (As already said, it's not a good idea to do this, but if you are going to do it anyway you need the correct syntax.) This is also the case when using --all-databases, so I cannot explain how it works there. That format (with a space between -p and the password) does not work for me with --all-databases.

    Also, the extra spaces in the date command arguments do not work either.
    Code:
    $ date + \% F _ \% T
    date: extra operand ‘%’
    Try 'date --help' for more information.
    $ date +\%F_\%T
    2020-02-25_13:54:21

  10. #10
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: mysqldump

    Quote Originally Posted by paweltech View Post
    Using the --all-databases option, in case you want to restore a single db, how should I operate ?
    Each database will begin with a "-- Current Database" comment and a CREATE DATABASE command like this:

    Code:
    --
    -- Current Database: `anklaw`
    --
    
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ `anklaw` /*!40100 DEFAULT CHARACTER SET latin1 */;
    
    USE `anklaw`;
    Find the one that corresponds to the database you're trying to recover. Copy from there to the next entry, paste it into a file, then run it from the command prompt using the mysql client.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •