Score:1

What is the proper way to back up ISC DHCPd lease files?

ธง ma

According to this answer, DHCPd lease files are cleared every hour. The goal is to back up the leases file continuously, so there is never a lease lost. This is made difficult since it is unclear whether the hour timer is based on system time (eg the file is rewritten at 1am, 2am, 3am etc) or process time (service_start + 1h, service_start + 2h, etc). Say the leases file is cleared at exactly 3am, and a lease is granted at 2:58:55; the service that backs up the lease file would need to run, quickly, before the file is cleaned.

The DHCPd process makes its own backup of the file to /var/lib/dhcpd/dhcpd.leases~. The best bet then seems to be to make a script that backs up this file to another location every hour. But if the DHCPd process is restarted and the timer is relative to the process, it would be possible for the hour mark on the backup tasks to align, which might end in one process reading while the other writes, and that could mangle the file (depending on how it's done). So the backup task would need some knowledge of when DHCPd starts. This is getting complicated.

What is the 'correct' way to back up the DHCPd leases file, so no leases are lost?

cn flag
แค่ความคิดของฉันจากการอ่านสิ่งนี้: ตามเหตุการณ์ (เช่น inotify) ทริกเกอร์เมื่อ `dhcpd.leases~` ใหม่ถูกปิด?
Score:1
ธง cl
A.B

จาก แหล่งที่มาของ DHCP:

      ถ้า (snprintf (backfname, sizeof backfname, "%s~", path_dhcpd_db) >= sizeof backfname)

[...]

      ถ้า (ยกเลิกการเชื่อมโยง (backfname) < 0 && errno != ENOENT) { 

[...]

      ถ้า (ลิงค์ (path_dhcpd_db, backfname) < 0) { 

ไฟล์สำรองข้อมูลก่อนหน้าจะถูกลบออก จากนั้นไฟล์เช่าปัจจุบันจะถูกฮาร์ดลิงก์เป็นข้อมูลสำรองโดยมีการต่อท้าย ~.

บน Linux ด้วย แจ้งเตือน(7) สิ่งอำนวยความสะดวกเหตุการณ์ ฮาร์ดลิงก์ถูกมองว่าเป็นเหตุการณ์การสร้าง

ฉันอยากจะแนะนำให้ใช้ แจ้งเตือน (จาก เครื่องมือ inotify package) เพื่อส่งสัญญาณเมื่อเหตุการณ์ดังกล่าวเกิดขึ้น เราควรคาดหวังการปรากฏของ /var/lib/dhcpd/dhcpd.leases~ ซึ่งพร้อมสำหรับการสำรองข้อมูลโดยตรง (เป็นฮาร์ดลิงก์ไปยังต้นฉบับ) เนื่องจากไฟล์จะเป็นไฟล์ที่แตกต่างกัน (ไอโหนดที่แตกต่างกัน) ในแต่ละครั้ง จึงเป็นไดเร็กทอรีที่ควรได้รับการตรวจหาที่เหมาะสม และตัวอย่างเช่น --รวม สามารถใช้ตัวเลือกเพื่อทำให้การประมวลผลเชลล์ง่ายขึ้น (ไม่มีการประมวลผล แม้แต่บรรทัดที่อ่านก็ถูกละทิ้งในตัวแปรจำลอง):

inotifywait -m -e สร้าง --include dhcpd.leases~ /var/lib/dhcpd | ในขณะที่อ่านดัมมี่ ทำ
    do_backup /var/lib/dhcpd/dhcpd.leases~
เสร็จแล้ว

หากคำสั่งไม่ใหม่พอ คำสั่งนั้นอาจไม่เข้าใจ --รวม ในกรณีเช่นนี้ จะต้องทำการทดสอบใน event loop:

inotifywait -m -e สร้าง /var/lib/dhcpd | ในขณะที่อ่านชื่อไฟล์เหตุการณ์ -r dir; ทำ
    ถ้า [ "$filename" = dhcpd.leases~ ]; แล้ว
        do_backup /var/lib/dhcpd/dhcpd.leases~
    ไฟ
เสร็จแล้ว

อีกทางหนึ่งคือ อินครอน แพ็คเกจ (มีอย่างน้อยบน CentOS 8 Stream) สามารถใช้ได้กับไฟล์ รายการ คล้ายกับ:

/var/lib/dhcpd IN_CREATE,recursive=false if_correct_file_do_backup $#

กับ if_correct_file_do_backup ตัวอย่างเช่น เชลล์กำลังตรวจสอบว่านี่คือชื่อไฟล์ที่ต้องการ:

#!/bin/sh

ถ้า [ "$1" = dhcpd.leases~ ]; แล้ว
    do_backup /var/lib/dhcpd/dhcpd.leases~
ไฟ

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา