การสำรองแฟ้ม access.log เป็นชื่อแฟ้มที่มีวันที่กำกับด้วย batch file

backup access.log
backup access.log

การสั่ง backup แฟ้ม แล้วได้ชื่อแฟ้มเป็นวันที่ปัจจุบัน อาจมีหลายวิธี
แต่วิธีที่ง่ายคือใช้ batch file ถูกสั่งงานผ่าน schedule task
โดยคำสั่งใน batch file ก็จะต้องกำหนดวันที่ให้กับแฟ้มเป้าหมาย
ซึ่งคำสั่ง dos ที่สามารถใช้ substring คือ :~ ตามด้วยตำแหน่งของข้อมูล
การนับตำแหน่งเริ่มต้น นับเหมือนจาวาคือ เริ่มตำแหน่งที่ 0

DOS>set f=access%date:~10%%date:~4,2%%date:~7,2%.log
DOS>copy access.log %f% |echo y
การสำรอง access.log ของ squid
ต้องดำเนินการให้สอดรับกับพรบ.คอมพิวเตอร์ 2550
ที่กำหนดให้เก็บ log อย่างน้อย 90 วัน

Author: บุรินทร์ รุจจนพันธุ์

I am Lecturer, Developer, Researcher, Columnist, Writer, Photographer, and Webmaster - L@mpang man

One thought on “การสำรองแฟ้ม access.log เป็นชื่อแฟ้มที่มีวันที่กำกับด้วย batch file”

  1. ขอบคุณครับ ผมนำไปประยุกต์ใช้แบบนี้ครับ

    cd C:\squid\sbin
    Squid -r
    cd C:\squid\var\logs
    REN access.log access_%date:~10%%date:~4,2%%date:~7,2%.log
    cd C:\squid\sbin
    squid -z
    squid -i -f c:/squid/etc/squid.conf -n Squid
    net start Squid

    เผื่อใครจะเอาไปประยุกต์ใช้ต่อครับ

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.