VZ6 Evacuate Server Script?

Discussion in 'General Questions' started by futureweb, Aug 2, 2016.

  1. futureweb

    futureweb Tera Poster

    Messages:
    390
    Hello,
    anyone already created an Evacuate Server Script for VZ6+PStorage and is willing to share? ;-)
    Otherwise I guess I have to write my own ... maintain original CT allocations, check for running Backups, what else to check?!
    thx
    Andreas Schnederle-Wagner
     
  2. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    Make sure container is not locked by any process (check /vz/lock/<ctid>* files).
    Except for this - nothing comes to my mind
     
  3. futureweb

    futureweb Tera Poster

    Messages:
    390
    alright - evac script is almost done ... one further question - is there any possibility to figure out if there are active "vzctl enter CTID" Sessions?
    As those prevent --online migration ... :-/
    thx
     
  4. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    There is no "native" way to figure that out I guess, just the scripting, like:
    Code:
    # CTID=123; vzps ax -E 0 -o cmd | awk '/^vzctl enter/' | grep -w $CTID && echo enter is running || echo enter is not running
    
     
    futureweb likes this.
  5. futureweb

    futureweb Tera Poster

    Messages:
    390
    that's doing it's job ... thx 4 fast & efficient help as always! ;-)
     
  6. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    I'd recommend you to check "exec" presence as well - e.g. "vzctl exec CTID top" would keep exec running and would prevent migration as well
     
  7. futureweb

    futureweb Tera Poster

    Messages:
    390
    alright - thx - will add this check too! ;-)

    any other command you can think of which would keep exec running? as top is not working - and I need one to see if check is working ... ;-)
     
  8. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    Code:
    #vzctl exec CTID sleep 10000
    
    :)
     
  9. futureweb

    futureweb Tera Poster

    Messages:
    390
    alright ... no comment on that ... lol ... sry ;-)

    *this very moment when you feel really dumb*
     
  10. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    Well... I did fail with "top" too, so I kind of understand how you feel....
     
  11. futureweb

    futureweb Tera Poster

    Messages:
    390
    hehe ;-)

    alright ... now I do checks for:
    - VZ locks - if [ -f "$lockDir$ctID.lck" ]
    - vzctl enter - if [[ $(vzps ax -E 0 -o cmd | awk '/^vzctl enter/' | grep -w $ctID) ]]
    - vzctl exec - if [[ $(vzps ax -E 0 -o cmd | awk '/^vzctl exec/' | grep -w $ctID) ]]
    - our BackupPC Backup Solution - if [[ $(/bin/ps aux | grep rsync | grep /vzCT$ctID) ]];
    - active tsnapshots (BackupPC) - TSNAPSHOT_COUNT=$(ploop snapshot-list /vz/private/$ctID/root.hdd/DiskDescriptor.xml | wc -l) [[ $TSNAPSHOT_COUNT != 2 ]] && { ...
    - and vzmigrate --dry-run on all CT IDs

    Guess that's enough - will add more checks if I run into problems ... ;-)
    (what comes into my mind: running PVA CT Backups, maybe check for mounted snapshot ploop devices?! or will "vzmigrate --dry-run" return Error if such a Backup is running?)

    As always - thx for your help!! :)
     
  12. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    Just checked - no, container is not locked during the backup. AFAIK there is an open bug for it.
    In that case migration will be attempted, and "dry-run" succeeds.

    I'll think of a way to detect this reliably and will let you know later
     
  13. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    Ok, I think I've found an elegant way to check this.
    Following short script would cover both PVA backup and prlctl backup:

    Code:
    # for pid in $(pidof vzlpl prl_backup_client); do ls -l /proc/$pid/fd/;done | grep "/dev/ploop" && echo "Achtung! Some backup is running!" || echo "Sector clear, no backups running spotted."
    
    Note, this script assumes you're not using vzfs-based containers, only ploop-based ones.
     
  14. futureweb

    futureweb Tera Poster

    Messages:
    390
    alright - all our CTs are ploop based - so this should be no problem!
    Would it also be possible to check on a "per CT base" if backup is running?
    If I do an "evacuate" - it's ok to check on all CTs - but if I do a "migrate back" - I only need to check for the CT IDs I migrate back to original Server - wouldn't be a problem if Backups are running on the CTs remaining on the Server ...

    thx for your help! ;-)
     
  15. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    That will be a bit more complicated and less elegant to check that on per-ct basis.
    You can do that by checking exact "/dev/ploopXXXX" instead of just "/dev/ploop", and retrieve "dev-ploop" from "ploop list" command
     
  16. futureweb

    futureweb Tera Poster

    Messages:
    390
    alright - most likely it's enough to check for the presence of running backups ... will "fine-tune" if i run into troubles with migrating back! ;-)
    thx!
     
  17. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    One thing was troubling me the whole discussion:

    Code:
    - active tsnapshots (BackupPC) - TSNAPSHOT_COUNT=$(ploop snapshot-list /vz/private/$ctID/root.hdd/DiskDescriptor.xml | wc -l) [[ $TSNAPSHOT_COUNT != 2 ]] && { ...
    
    instead of "!=2" I'd check "-lt 2" - if there are 3 deltas for some reason this check wont detect it.
     
  18. futureweb

    futureweb Tera Poster

    Messages:
    390
    I echo a warning if line count is not 2 - 2 is standard when no snapshots/tsnapshots are present (headline + Base Delta)
    Will also trigger if a real (wanted) Snapshot is present ... not only on Backup tsnapshots

    So I guess this should be ok?! Or do I have a thinking error?


    Code:
    for ctID in $ctIDs; do
      if isnumber $ctID && [ "$ctID" -gt "1" ]; then
         TSNAPSHOT_COUNT=$(ploop snapshot-list /vz/private/$ctID/root.hdd/DiskDescriptor.xml | wc -l)
         [[ $TSNAPSHOT_COUNT != 2 ]] && {
          echo -e "${RED}CT $ctID - Multiple Snapshots found!! ploop snapshot-list /vz/private/$ctID/root.hdd/DiskDescriptor.xml - vzctl tsnapshot-delete $ctID --id ${NC}";
          errorMsg="$errorMsg\nCT $ctID - Multiple Snapshots found!! ploop snapshot-list /vz/private/$ctID/root.hdd/DiskDescriptor.xml - vzctl tsnapshot-delete $ctID --id "
    
          if [ "$doWork" != "checkonly" ]; then
               doExit="true"
          fi
         }
       fi
    done
    
    (no comments on my variable naming!! ;-))
     
  19. Pavel

    Pavel A.I. Auto-Responder Odin Team

    Messages:
    416
    No, it's ok, you're correct. I just didn't account the header line.
     
  20. futureweb

    futureweb Tera Poster

    Messages:
    390
    Well - I guess at the time the Script is finished we are already on VZ7 with rebootless updates - so no more evac script is needed ... lol ;-)
     

Share This Page