Back up a database using systemd timer
Back up a database using systemd timerGuideMajor Linux distributions use systemd instead of System V boot. systemd timer can replace most functions of crontab scheduled tasks. This article describes how to back up a database using systemd timer. Other types of scheduled tasks can be implemented in the same way.
Define timer filesEnter the/usr/lib/systemd/system directory and create a timer according to the following file:
[Unit]Description=Runs db backup every hour[Timer]# Time to wait after booting before we run first timeOnBootSec=10min# Time between running each consecutive timeOnUnitActiveSec=1hUnit=db_backup.service[Install]WantedBy=multi-user.target
Define service filesGo to the/usr/lib/systemd/system directory and create a service as follows:
[Unit]Description=Backup database[Service]Type=simpleExecStart=/usr/local/bin/db_backup
Write database backup scriptCreate the file/usr/local/bin/db_backup and write the database backup statement, for example:
#!/usr/bin/bash/usr/bin/mysqldump -umy_username -pmy_password -h192.168.1.xx --databases my_database > /path/to/backup/dir/my_database.`date +'%Y%m%d%H%'`.sql
Enable and run timerRun the following command on the command line:
systemctl enable db_backup.timersystemctl start db_backup.timer
After the scheduled task is executed, the database backup file is generated in the Database Backup Directory.
Address: http://joelhy.github.io/2015/06/18/backup-database-using-systemd-timer/
Address: http://www.linuxprobe.com/systemd-timer-mysql.html ghost
GuideMajor Linux distributions use systemd instead of System V boot. systemd timer can replace most functions of crontab scheduled tasks. This article describes how to back up a database using systemd timer. Other types of scheduled tasks can be implemented in the same way.Define timer filesEnter the/usr/lib/systemd/system directory and create a timer according to the following file:
[Unit]Description=Runs db backup every hour[Timer]# Time to wait after booting before we run first timeOnBootSec=10min# Time between running each consecutive timeOnUnitActiveSec=1hUnit=db_backup.service[Install]WantedBy=multi-user.target
Define service filesGo to the/usr/lib/systemd/system directory and create a service as follows:
[Unit]Description=Backup database[Service]Type=simpleExecStart=/usr/local/bin/db_backup
Write database backup scriptCreate the file/usr/local/bin/db_backup and write the database backup statement, for example:
#!/usr/bin/bash/usr/bin/mysqldump -umy_username -pmy_password -h192.168.1.xx --databases my_database > /path/to/backup/dir/my_database.`date +'%Y%m%d%H%'`.sql
Enable and run timerRun the following command on the command line:
systemctl enable db_backup.timersystemctl start db_backup.timer
After the scheduled task is executed, the database backup file is generated in the Database Backup Directory.
Address: http://joelhy.github.io/2015/06/18/backup-database-using-systemd-timer/
Reprinted address: http://www.linuxprobe.com/systemd-timer-mysql.html ghost