Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Back in the day when i was using windows(and a noob at everything IT) i liked batch scripting so much that i wrote a lot of them and one i am pretty proud of that is my backup.cmd(see below).

I am pretty basic with the linux bash sudo/apt-get/sl/ls/locate
/updatedb/etc...

I don't really know the full power of the terminal. If you see the code below can i get it to work under (Ubuntu)linux :) by rewriting some of the windows code with the linux equivalent (btw:this works under xp/vista/7 | dutch/english)

@echo off
title back it up
:home
cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º                                                      º
echo º typ A/B for the options                              º
echo º                                                      º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º                                                      º
echo º "A"=backup options                                   º
echo º                                                      º
echo º "B"=HARDDISK Options                                 º
echo º                                                      º
echo º                                                      º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
set /p selection=Choose:
Goto %selection%
:A
cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º                                                      º
echo º typ 1 to start that backup                           º
echo º                                                      º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º                                                      º
echo º "A"=backup options                                   º
echo º  È1=Documents,Pictures,Music,Videos,Downloads        º
echo º                                                      º
echo º "B"=HARDDISK Options                                 º
echo º                                                      º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
set /p selection=Choose:
Goto %selection%
:B
cls
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º                                                      º
echo º typ HD to start the disk check                       º
echo º                                                      º
echo ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹
echo º                                                      º
echo º "A"=backup options                                   º
echo º                                                      º
echo º "B"=HARDDISK Options                                 º
echo º  ÈHD=find and repair bad sectors                     º
echo º                                                      º
echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ
set /p selection=Choose:
Goto %selection%

:1
cls
if exist "%userprofile%\desktop" (set desk=desktop) else (set desk=Bureaublad)
if exist "%userprofile%\documents" (set docs=documents) else (set docs=mijn documenten)
if exist "%userprofile%\pictures" (set pics=pictures) else (echo cant find %userprofile%\pictures)
if exist "%userprofile%\music" (set mus=music) else (echo cant find %userprofile%\music)
if exist "%userprofile%\Videos" (set vids=videos) else (echo cant find %userprofile%\videos)
if exist "%userprofile%\Downloads" (set down=downloads) else (echo cant find %userprofile%\Downloads)
cls
echo. examples (D:\) (D:\Backup) (D:\Backup\18-4-2011)
echo.
echo. if there is no "D:\backup" folder then the folder will be created
echo. 
set drive=
set /p drive=storage:
echo start>>backup.log
echo Name:%username%>>backup.log
echo Date:%date%>>backup.log 
echo Time:%time%>>backup.log
echo ========================================%docs%===========================================>>backup.log
echo %docs%  
echo Source:"%userprofile%\%docs%" 
echo Destination:"%drive%\%username%\%docs%"
echo %time%>>backup.log
xcopy "%userprofile%\%docs%" "%drive%\%username%\%docs%" /E /I>>Backup.log
echo 20%%
cls
echo ========================================"%pics%"=========================================>>backup.log
echo "%pics%" 
echo Source:"%userprofile%\%pics%" 
echo Destination:"%drive%\%username%\%pics%"
echo %time%>>backup.log
xcopy "%userprofile%\%pics%" "%drive%\%username%\%pics%" /E /I>>Backup.log
echo 40%%
cls
echo ========================================"%mus%"=========================================>>backup.log
echo "%mus%" 
echo Source:"%userprofile%\%mus%" 
echo Destination:"%drive%\%username%\%mus%" 
echo %time%>>backup.log
xcopy "%userprofile%\%mus%" "%drive%\%username%\%mus%" /E /I>>Backup.log
echo 60%%
cls
echo ========================================"%vids%"========================================>>backup.log
echo %vids% 
echo Source:"%userprofile%\%vids%" 
echo Destination:"%drive%\%username%\%vids%"
echo %time%>>backup.log
xcopy "%userprofile%\%vids%" "%drive%\%username%\%vids%" /E /I>>Backup.log
echo 80%%
cls
echo ========================================"%down%"========================================>>backup.log
echo "%down%" 
echo Source:"%userprofile%\%down%" 
echo Destination:"%drive%\%username%\%down%"
echo %time%>>backup.log
xcopy "%userprofile%\%down%" "%drive%\%username%\%down%" /E /I>>Backup.log
echo end>>backup.log
echo %username% %date% %time%>>backup.log
echo 100%%
cls
echo backup Compleet

copy "backup.log" "%drive%\%username%"
del "backup.log"
pushd "%drive%\%username%"
echo close backup.log to continue with backup script
"backup.log"
echo press any key to retun to the main menu
pause>nul
goto :home

:HD
echo finds and repairs bad sectors
echo typ in harddisk letter (C: D: E:)
set HD=
set /p HD=Hard Disk:
chkdsk %HD% /F /R /X
pause
goto :home
share|improve this question
    
I see that its beautiful, but do you want a complete rewrite for a bash- equivalent from community or just directions would help? –  Mahesh Apr 12 '12 at 19:26
    
Read this answer on SuperUser: superuser.com/questions/29232/linux-equivalent-to-robocopy –  djangofan Apr 12 '12 at 22:10
add comment

3 Answers 3

up vote 1 down vote accepted

It would be very similar, but you'll have to change a lot of syntax. run man bash and man cp for a lot of info. For this script, cp is the command doing most of your heavy lifting. It will replace copy and xcopy. Echo is still echo. You can write to your log with the '>>' operator.

Bash is pretty neat because you can define functions and use real if if(...){... } else{ ...}statements instead of if ... goto (you can still use labels if you really want). Try learning bash just like you learned batch, and enjoy finding your way around. You'll be glad you took the time to rewrite this script from the ground up, and you will learn about a lot of new tools.

share|improve this answer
    
set /p selection=Choose: Goto %selection%< can i still use this or do i have to use something else? –  blade19899 Apr 12 '12 at 20:56
    
@blade19899 You can use read -p "Choose:" selection for that. I suggest you to drop the batch script and make a list of requirements, such as "menu choice". When searching, add "bash" to it. Using that, I found fancy answers like serverfault.com/q/144939/51929 –  Lekensteyn Apr 12 '12 at 21:19
add comment

I would recommend that you familiarize yourself with Python. It's a very nice and easy to learn language. No compiles or anything like that. However, it has libraries that enables you do do anything you would want to do.

So, you might want to first a text-based replacement for your current script. Then, later, you can add a GUI for it. It's easy. Of course, Bash is useful too, but more limited. If you're going to only learn one new language, I would absolutely recommend Python. But of course, there's nothing wrong with learning both Bash and Python :)

share|improve this answer
add comment

I think most people would suggest "rsync", which is basically the closest thing to Microsoft RoboCopy that there is:

http://superuser.com/questions/29232/linux-equivalent-to-robocopy

That batch file is basically overdoing it a little, IMHO.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.