-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
backups.sh
26 lines (23 loc) · 816 Bytes
/
backups.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
echo -n "Enter the MySQL root password: "
read -s root_password
echo
# Check the password by trying to access MySQL
mysql -u root -p${root_password} -e "exit"
if [ $? -ne 0 ]; then
echo "Invalid password. Exiting."
exit 1
fi
# Get the list of databases, excluding the system databases
databases=$(mysql -u root -p${root_password} -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema|mysql|sys)")
for db_name in $databases
do
backup_file=$(date +'%Y-%m-%d-%H-%M-%S')
backup_dir="/home/ismoilovdevarchlinux/3backup-mysql/${db_name}/"
echo $backup_dir
if [ ! -d $backup_dir ]; then
mkdir -p $backup_dir
fi
# Dump each database in a separate file
mysqldump -u root -p${root_password} $db_name > "${backup_dir}${backup_file}.sql"
done