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 ...
- 11-03-2011 #1Just 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?
thanks in advanceHTML 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 doneLast edited by razstec; 11-03-2011 at 10:07 AM.
- 11-03-2011 #2Just Joined!
- Join Date
- Sep 2011
- Posts
- 19
solve it like this
Now, any ideas on the restore point and text option?Code:now=$(date +"%a_%b_%Y-%H:%M:%S")
- 11-03-2011 #3Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I'm not sure what your code is trying to do (no hablo), but i think this is what you need - replace this bit:
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?Code:if [ "$text" = "s" ] || [ "$text" = "S" ]; then
- 11-04-2011 #4Just Joined!
- Join Date
- Jul 2007
- Location
- Chennai, India
- Posts
- 8
I think that in the restore options, you should prompt and get the date and time of the file to restore.
OK
- 11-07-2011 #5Just 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)
- 11-07-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
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.:
versus:Code:# variable assignment [ $text="s" ]
Code:# string comparison [ "$text" = "s" ]
- 11-07-2011 #7Just 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
- 11-07-2011 #8Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
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.
- 11-07-2011 #9Just Joined!
- Join Date
- Sep 2011
- Posts
- 19
cant seem to work now :S now it starts and closes right away.... havent change anything :s
- 11-07-2011 #10Linux Guru
- Join Date
- May 2011
- Posts
- 1,843
I cut-and-pasted your code above and it works for me. Did you add looping code and that is what broke it?


Reply With Quote