在 MySQL 中创建一个计时器
我有一个备份系统......每 5 分钟备份一个文件夹。可以使用 IP 地址将备份分配给任何设备。但是设备每周或每月重新启动一次,我们希望每周或每月的特定时间、特定秒数关闭备份。创建数据库表应该不是问题,我想知道是否有任何方法可以在函数中执行此操作
表的结构如下
Device
Id BIGINT(20), //Auto Increment Id of the Device
Name VARCHAR(255), //Name of the device
Backup TINYINT(1) //Boolean to represent weather the device is backed or not
TurnOffBackup
Id BIGINT(20), //Id of the Table
deviceId BIGINT(20), //DeviceId Foriegn Key
weekDay TINYINT(1), //The week day to turn it off
monthDate INT(2), //The month date to turn it off
fortime BIGINT(20) //The number of seconds to turn the device off for
在我选择要备份的设备如下
SELECT * FROM Device WHERE backup=1
我想要实现的是
SELECT * FROM Device WHERE backup=1 AND TURNBACKUPOFF(Device.Id)=0
知道我将如何执行此操作,或者我应该考虑在代码中而不是在 MySQL 函数中执行此操作
I have a backup system..... that backs up a folder every 5 minutes. The backup can be assigned to any device using its IP Address. But once a week or once a month that device is rebooted, and we want to turn the backup off every week or month on a certain time for certain seconds. Creating the database table shouldn't be a problem, I was wondering if there is any way we can do this in a function
The Tables are structured as below
Device
Id BIGINT(20), //Auto Increment Id of the Device
Name VARCHAR(255), //Name of the device
Backup TINYINT(1) //Boolean to represent weather the device is backed or not
TurnOffBackup
Id BIGINT(20), //Id of the Table
deviceId BIGINT(20), //DeviceId Foriegn Key
weekDay TINYINT(1), //The week day to turn it off
monthDate INT(2), //The month date to turn it off
fortime BIGINT(20) //The number of seconds to turn the device off for
At the moment my select for devices to be backedup are as follows
SELECT * FROM Device WHERE backup=1
What i wana achieve is
SELECT * FROM Device WHERE backup=1 AND TURNBACKUPOFF(Device.Id)=0
Any idea how i would do this or should i be considiring doing this in code rather than in a MySQL Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用 id INT 和 backupEnabled BOOLEAN 并使用 cron 脚本或 Quartz 来启用/禁用备份。更准确地说,我会从导致重新启动的同一脚本中更新此内容。重复重启时间是没有用的并且容易出错。
I'd use
id INT
andbackupEnabled BOOLEAN
, and use a cron script or Quartz to enable/disable backups. More precisely, I'd update this from the same script which is causing the reboot. Duplicating the time of reboot is useless and error-prone.