• Home
  • Downloads
  • Contact Us
  • Report Broken Link
Friday, May 9, 2025
  • Login
lessons4you.info
  • Videos
  • Downloads
  • Help
    • Contact Us
    • Report Broken Link
No Result
View All Result
  • Videos
  • Downloads
  • Help
    • Contact Us
    • Report Broken Link
No Result
View All Result
Lessons4you.info
No Result
View All Result

How to Update Galaxy Ace 2 I8160 with Android 4.1.2 XXMF2 Jelly Bean Official Firmware

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

How to Take Automatic MySQL Database Backup Using Shell Script and Cron Job

by
December 11, 2021
in Uncategorized
Reading Time: 1 min read
A A
Share on FacebookShare on Twitter

Write a script to take auto backup of MySQL database using Cronjob. First of all create a seperate sql backup directory in home folder to keep all your sql backup file. Then create the “mysqlbackup.sh” script file in “/usr/local/sbin/” folder.

1
2
3
 
$ mkdir /home/sqlbackup
 

Now, create “Script” folder in your home directory and create your “mysqlbackup.sh” script file in this folder.

1
2
3
 
$ sudo vi /usr/local/sbin/mysqlbackup.sh
 

1
2
3
4
5
6
7
8
9
10
11
12
13
 
#!/bin/bash
datum=`/bin/date +%Y%m%d-%H`
/usr/bin/mysqladmin --user=root --password=yourmysqlpassword stop-slave
/usr/bin/mysqldump --user=root --password=yourmysqlpassword --lock-all-tables \
     --all-databases > /home/sqlbackup/backup-${datum}.sql
/usr/bin/mysqladmin --user=root --password=yourmysqlpassword start-slave
for file in "$( /usr/bin/find /home/sqlbackup -type f -mtime +2 )"
do
/bin/rm -f $file
done
exit 0
 

Note: Change username and password accoding to your database.
Code Explanation: “-mtime +2” means files that are more than 2 days old If you want to keep backup file older than 2 days then you have to change it’s value. Otherwise it will delete the backup files older than 2 days. Give execute permittion to this script.

1
2
3
 
$ sudo chmod +x /usr/local/sbin/mysqlbackup.sh
 

Final setp is set the cronjob. This cronjob will run every 3 hours so it will backup 4 times in a day. You can chage the time by editing the cronjob. For more information about cronjob see manual.

1
2
3
 
0 */3 * * * /usr/local/sbin/mysqlbackup.sh &> /dev/null
 

You can setup a FTP connection to copy this backup file to a remote server for more security.

Previous Post

How to Update Galaxy Ace 2 I8160 with Android 4.1.2 XXMF2 Jelly Bean Official Firmware

Next Post

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

Related Posts

How To Install The TWRP Recovery on Xiaomi Redmi 1s
Uncategorized

How To Install The TWRP Recovery on Xiaomi Redmi 1s

May 14, 2022
MIUI Collection Of Gapps (2.3.x – 5.0.x)
Uncategorized

MIUI Collection Of Gapps (2.3.x – 5.0.x)

May 14, 2022
Download Android 5.1.x Lollipop PA Gapps
Uncategorized

Download Android 5.1.x Lollipop PA Gapps

May 15, 2022
Download gapps for Android 5.1 Lollipop Cyanogemod 12.1
Uncategorized

Download gapps for Android 5.1 Lollipop Cyanogemod 12.1

May 14, 2022
Reddit AMA with OxygenOS Team OnePlus
Uncategorized

Reddit AMA with OxygenOS Team OnePlus

May 14, 2022
How to Remove Adobe Updater from OS X Menu Bar?
Uncategorized

How to Remove Adobe Updater from OS X Menu Bar?

July 19, 2023
Next Post

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

  • Home
  • Downloads
  • Contact Us
  • Report Broken Link

© 2022 lessons4you.info

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Videos
  • Downloads
  • Help
    • Contact Us
    • Report Broken Link

© 2022 lessons4you.info