Find the answer to your Linux question:
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21
Hi all, i have a script to backup my db, the problem is that it backups with the data it was created in the name, the second part of the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19

    list folder


    Hi all, i have a script to backup my db, the problem is that it backups with the data it was created in the name, the second part of the script is to restore data and thats where the problem begins, how can i solve this since the file name is diferent?

    By the way why dont it stops when i press n in text?

    HTML Code:
    now=$(date +"%m_%d_%Y")
    #!/bin/bash
    
    selection=
    until [ "$selection" = "0" ]; do
        echo ""
        echo Manutencao de BD 
        echo - - - -- - - - - -
        echo Backup
        echo 1. Backup Diario
        echo 2. Backup Semanal
        echo 3. Backup Mensal
        echo - - - - - - - - - -
        echo Restauro
        echo 4. Restauro Diario
        echo 5. Restauro Semanal
        echo 6. Restauro Mensal
        echo - - - - - - - - - -
        echo 7. Sair
        echo ""
        echo -n "Escolha uma opcao: "
        read selection
        echo ""
    
            echo -n "Tem a certeza?(s/n) "
            read text
            
    if [ $text="s" ] | [ $text="S" ]; then
            
        case $selection in
            1 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup Diario/Backup_oc_diario_$now" openclinica;; 
            
            2 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup Semanal/Backup_oc_semanal_$now" openclinica;;
    
            3 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup Mensal/Backup_oc_mensal_$now" openclinica;;
            
            4 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format custom --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_oc_diario_$now" openclinica;;
            
            5 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format custom --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_oc_semanal_$now" openclinica;;
    
            6 ) /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format custom --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_oc_mensal_$now" openclinica;;
    
            7 ) exit ;;
            * ) echo "Escolha uma das opções apresentadas no menu"
        esac
    
    else
    exit
    
    fi
    
    done
    thanks in advance
    Last edited by razstec; 11-03-2011 at 10:07 AM.

  2. #2
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    solve it like this
    Code:
    now=$(date +"%a_%b_%Y-%H:%M:%S")
    Now, any ideas on the restore point and text option?

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    I'm not sure what your code is trying to do (no hablo), but i think this is what you need - replace this bit:

    Code:
    if [ $text="s" ] | [ $text="S" ]; then
    with this:

    Code:
    if [ "$text" = "s" ] || [ "$text" = "S" ]; then
    I don't understand your question about restoring and the file name having changed. Can you be more specific?

  4. #4
    Just Joined!
    Join Date
    Jul 2007
    Location
    Chennai, India
    Posts
    9
    I think that in the restore options, you should prompt and get the date and time of the file to restore.

    OK

  5. #5
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    Hi, i actually have the script working like this

    now=$(date +"%d_%b_%Y-%H:%M:%S")
    #!/bin/bash

    selection=
    until [ "$selection" = "0" ]; do
    echo ""
    echo Manutencao de BD
    echo - - - - - - - - - -
    echo Backup
    echo 1. Backup Diario
    echo 2. Backup Semanal
    echo 3. Backup Mensal
    echo - - - - - - - - - -
    echo Restauro
    echo 4. Restauro Diario
    echo 5. Restauro Semanal
    echo 6. Restauro Mensal
    echo - - - - - - - - - -
    echo 7. Sair
    echo ""
    echo -n "Escolha uma opcao: "
    read selection
    echo ""

    echo -n "Tem a certeza?(s/n) "
    read text

    if [ $text="s" ] | [ $text="S" ]; then

    case $selection in
    1 )
    mv /home/oc/Desktop/Backup_OC/Backup_Diario/* /home/oc/Desktop/Backup_OC/Backup_Diario_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Diario/Backup_oc_diario_$now" openclinica
    echo
    echo ::::Backup Diario Efectuado com Sucesso::::;;

    2 )
    mv /home/oc/Desktop/Backup_OC/Backup_Semanal/* /home/oc/Desktop/Backup_OC/Backup_Semanal_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Semanal/Backup_oc_semanal_$now" openclinica
    echo
    echo ::::Backup Semanal Efectuado com Sucesso::::;;

    3 )
    mv /home/oc/Desktop/Backup_OC/Backup_Mensal/* /home/oc/Desktop/Backup_OC/Backup_Mensal_old/
    /opt/PostgreSQL/8.4/bin/pg_dump --host localhost --port 5432 --username postgres --format tar --blobs --verbose --file "/home/oc/Desktop/Backup_OC/Backup_Mensal/Backup_oc_mensal_$now" openclinica
    echo
    echo ::::Backup Mensal Efectuado com Sucesso::::;;

    4 )
    cd /home/oc/Desktop/Backup_OC/Backup_Diario/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Diario/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Diario Efectuado com Sucesso::::;;

    5 )
    cd /home/oc/Desktop/Backup_OC/Backup_Semanal/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Semanal/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Semanal Efectuado com Sucesso::::;;

    6 )
    cd /home/oc/Desktop/Backup_OC/Backup_Mensal/
    for i in `ls -a *`
    do
    /opt/PostgreSQL/8.4/bin/pg_restore --host localhost --port 5432 --username postgres --dbname openclinica --list "/home/oc/Desktop/Backup_OC/Backup_Mensal/"$i"" openclinica
    done
    echo
    echo ::::Restauro DB Mensal Efectuado com Sucesso::::;;

    7 ) exit ;;
    * ) echo "Escolha uma das opções apresentadas no menu"
    esac

    else
    exit

    fi

    done

    The problem is that when i ask if im sure (Tem a certeza?(s/n)) s=yes, n=no, he always go true no matter what i press, i tryed with the two || and its the same.
    this part is just a simple are you sure? (y/n)

  6. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    What about the spaces before and after the '='? That is the main problem, I think. With no space, you are doing variable assignment, no string comparison. e.g.:

    Code:
     
    # variable assignment
    [ $text="s" ]
    versus:

    Code:
    # string comparison
    [ "$text" = "s" ]

  7. #7
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    it worked now only need a way to send the script to restart except if the option is 7

    thanks

  8. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    You mean make the menu reappear after the user has selected one of the options? Just wrap the whole thing in an endless loop. You're already doing an exit in case 7 (btw, the echo after the 'exit' won't appear b/c you are exiting first). You could also use a 'break' to jump out of the loop.

  9. #9
    Just Joined!
    Join Date
    Sep 2011
    Posts
    19
    cant seem to work now :S now it starts and closes right away.... havent change anything :s

  10. #10
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    I cut-and-pasted your code above and it works for me. Did you add looping code and that is what broke it?

Page 1 of 3 1 2 3 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •