在 MySQL 中创建一个计时器

发布于 2024-09-06 13:13:11 字数 962 浏览 1 评论 0原文

我有一个备份系统......每 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-09-13 13:13:11

我会使用 id INT 和 backupEnabled BOOLEAN 并使用 cron 脚本或 Quartz 来启用/禁用备份。更准确地说,我会从导致重新启动的同一脚本中更新此内容。重复重启时间是没有用的并且容易出错。

I'd use id INT and backupEnabled 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文