» »

Cron problem

Cron problem

poweroff ::

Imam naslednji scenarij.

Računalnik se uporablja (prižiga) samo vsake toliko. Včasih je prižgan vsak dan, včasih po več dni skupaj ne. Ta računalnik bi rad backupiral.

Backupe bi rad delal na naslednji način:
- backup se naredi enkrat tedensko, recimo vsak torek
- če v torek računalnik ni prižgan, se naredi takoj naslednjič, ko je prižgan
- recimo, da je prižgan v sredo... če se backup job zaključi v sredo, je to potem do naslednjega torka mir, če pa ne, se pa nadaljuje (ponovno požene) takoj, ko se računalnik spet prižge (recimo, da je to petek)

Kakšna ideja kako to najbolj elegantno narediti?
sudo poweroff

jukoz ::

Maš še kakšno mašino na tem omrežju? Ki je ob torkih prižgana =)

Randomness ::

Uporabljaš systemd? Potem to rešiš s timerji. Hint: vklopi opcijo Persistent
Systemd/Timers

joggi79 ::

Ali pa naredis skripto, ki ti jo cron laufa vsako minuto/vsako uro in ko delas backup ti skripta za backup naredi en "trigger file". Ce je starejsi kot 1 teden ti zacne backup, drugace pa konca.

poweroff ::

SystemD izgleda zanimivo, ampak bi se moral malo poglobiti.

Zaenkrat sem rešil kar na quick 'n' dirty way:

#!/bin/bash
FILE=/home/matej/bckptime.txt
REPEAT_AFTER_DAYS=7

if [ -f "$FILE" ]
then
  echo "File with backup status exists."
  if grep -q "Completed" "$FILE";
  then
    echo "Last backup has been completed, checking if backup is too old..."
    DIFF=$(( ($(date "+%s") - $(date -d $(stat -c %y "$FILE" | cut -d " " -f1) "+%s")) / (60*60*24) ))
    if [ $DIFF -gt $REPEAT_AFTER_DAYS ]
    then
      echo "Backup is 7 or more days old, starting new backup now..."
      echo "" > "$FILE"
      echo "RUNNING BACKUP..."
      echo "Completed" > "$FILE"
      echo "Backup completed!"
    else
      echo "Everything OK, backup is not too old."
    fi
  else
    echo "Last backup has NOT been successfully completed."
    echo "" > "$FILE"
    echo "RUNNING BACKUP..."
    echo "Completed" > "$FILE"
    echo "Backup completed!"
  fi
else 
  echo "File with backup status does not exists, creating it, and starting first backup..."
  touch "$FILE"
  echo "" > "$FILE"
  echo "RUNNING BACKUP..."
  echo "Completed" > "$FILE"
  echo "Backup completed!"
fi


Na prvi pogled izgleda da deluje... Namesto echo "RUNNING BACKUP..." bo seveda backup ukaz. Zadevo bom pa poganjal kar @reboot.
sudo poweroff

Zgodovina sprememb…

  • spremenilo: poweroff ()

c3p0 ::

anacron is the daemon that completes cron for computers that are not on at all times. Since regular tasks are usually scheduled for the middle of the night, they will never be executed if the computer is off at that time. The purpose of anacron is to execute them, taking into account periods in which the computer is not working.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

bash skripta ki bere txt

Oddelek: Programiranje
81116 (846) Mike0
»

Arhiviranje serverja s TAR - incremental in FTP na drugo lokacijo in email report - S

Oddelek: Operacijski sistemi
61577 (1488) Daedalus
»

Crontab in skripta v 8.04.2; kako?

Oddelek: Operacijski sistemi
91320 (1115) BigWhale
»

[bat datoteke] Trenutni datum in ura

Oddelek: Programiranje
112507 (2264) darkolord
»

Kako bi porezal vrednost (php) spremenljivki ?

Oddelek: Programiranje
15954 (750) Cokolesnik

Več podobnih tem