Search code examples
mysqllinuxlsgunzip

How to import latest database backup file to backup server


I want to import the backup database file in *.sql.gz to my backup server. I try to use the follow command but there is an error with it

ls -Art *.sql.gz | tail -n 1 | gunzip -c | mysql --user=user --password=password database
gzip: stdin: not in gzip format

So how can I pipe the latest files to gunzip is correct.


Solution

  • Try using xargs:

    ls -Art *.sql.gz |tail -n 1 |xargs gunzip -c | mysql --user=user --password=password database