MySQL backup script

Przemyslaw3 years ago

Zrobiłem wszystko od początku, łącznie z wywaleniem certbota, letsencrypt i apache2 i teraz wszystko mi działa, tylko nie rozumiem dlaczego instalując mysql-server ustawiam swoje hasło a potem muszę używać hasła root, np jak robię backup Twoim skryptem.
Pozdrawiam.

Mark3 years ago

How to resolve this error?
output:
./mysql-backup.sh: Permission denied

Slawek3 years ago

try
chmod 755 mysql-backup.sh

Mark3 years ago

i tried 755, 777, error output:
-bash: ./mysql-backup.sh: /bin/bash^M: bad interpreter: No such file or director

Mark3 years ago

the mysql dump command works as I modify the script to insert this command
mysqldump -u root -p traccar > traccar.sql
with automated user and password?

Slawek3 years ago

Try run from root directory

Mark3 years ago

i tried on root directory and on root folder. Not work :(

root@ubuntu:~# ./mysql-backup.sh
bash: ./mysql-backup.sh: Permission denied ( root folder)
root@ubuntu:~# bash: ./mysql-backup.sh: No such file or directory ( root directory)
Slawek3 years ago

Did you do in root dir?
chmod 755 mysql-backup.sh
. /mysql-backup.sh

Mark3 years ago

yes, output is: -bash: ./mysql-backup.sh: /bin/bash^M: bad interpreter

Slawek3 years ago

did you edit this script under windows ?

Przemyslaw3 years ago

@Slawek jak zrobić restore MySQL Twoim skryptem?

Mark3 years ago

Thanks I fixed, it was a setting in the wrong notepad++ I had to set the software as unix for saving files. now it works.

if it can be useful for others this is the solution:
Unix uses different line endings so can't read the file you created on Windows. Hence it is seeing ^M as an illegal character. (My ERROR)
If you want to write a file on Windows and then port over, make sure your editor is set to create files in UNIX format.
In notepad++ in the bottom right of the screen, it tells you the document format. By default, it will say Dos\Windows. To change it go to
settings->preferences
new document / default directory tab
select the format as unix and close
create a new document

Slawek3 years ago

@Przemyslaw
np:
gunzip 2021-03-14-traccar.gz
mysql -u root -p traccar < 2021-03-14-traccar

Mark3 years ago

@Slawek
Just the command you're reporting or do you need a zip extractor?
my file is : 2021-03-14-traccar.gz
i need to install gunzip?
Thanks

Slawek3 years ago

should be in ubuntu system

gunzip 2021-03-14-traccar.gz
or
gzip -d 2021-03-14-traccar.gz