0

I'm working on ultimate backup script for very important server. My script already:

  • creates a backup
  • verifies copied file(-s)
  • verifies gz archive
  • compares MD5 on local and remote after sending file to remote server via scp
  • removes monthly backups older than 365, weekly backups older than 31 days, daily backups older than 7 days, hourly backups older than 24 hours
  • checks for available disk space on local and remote machine
  • sends email report if some errors ocurred
  • sends email report for weekly backups

In addition to all this, I miss one important thing - clock verification on local and remote because it affects the naming and removal of copies.

How can I make sure if date and time are set correctly in bash in a simple and reliable way?

If possible - it would be nice if that method could work on Windows server with cygwin.

I'm not asking for complete solution, just advice for taking correct and not complex approach.

Kamil
  • 157
  • 2
  • 10
  • See https://serverfault.com/questions/1077601/how-to-check-whether-the-system-time-is-synchronised-to-ntp-server-without-knowi – stark Jan 12 '23 at 17:33
  • @stark thats pretty complicated, I need some kind of bash one-two liner :) – Kamil Jan 13 '23 at 16:23

1 Answers1

1

You can use command in Linux:

date +%s

and in Windows (PowerShell)

Get-Date -UFormat %s

to get epoch time. Those numbers can be easy compared.

P.S. For Windows you may need to strip the number to integer like this:

$t3 = (Get-Date -UFormat %s).split(',')[0]
echo $t3

N.B. Here comma , is my decimal number delimiter. Depend of your language you may need to change it.

This command will give you Epoch time from external source (to compare with your machines)

curl -s "http://worldtimeapi.org/api/timezone/Europe/Rome" |jq '.unixtime'

Feel free to change your timezone

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
  • This is good to compare between two machines, but I need something that checks some reference ntp server. – Kamil Jan 13 '23 at 16:22
  • 1
    @Kamil In such case implement to ALL machines ntp clients – Romeo Ninov Jan 13 '23 at 16:24
  • I have ntp clients on all machines, but I need to be sure that it is working before I start deleting backups older than x days. – Kamil Jan 13 '23 at 17:13
  • 1
    @Kamil, will update the answer to give you time from World source – Romeo Ninov Jan 13 '23 at 17:22
  • 1
    Nice, pretty portable (available on cygwin, debian and I don't know what else) but it looks like I would have to to install curl on all servers. I think it is worth. – Kamil Jan 13 '23 at 20:27