# Backup Script



## rbizzell33 (Apr 13, 2010)

I want to do incremental backups but how do you put in the script for it to change the date and time so each script will have a date and the othetr scrpits won't get over written. Day, date time.  I will be running rysnc and taring the file up afterwards. Date% i can't remember exactly.


----------



## jalla (Apr 13, 2010)

rbizzell33 said:
			
		

> I want to do incremental backups but how do you put in the script for it to change the date and time so each script will have a date and the othetr scrpits won't get over written. Day, date time.  I will be running rysnc and taring the file up afterwards. Date% i can't remember exactly.



If you don't remember, try date(1) to refresh your memory. The manpage is full of examples


----------



## Orige (Apr 19, 2010)

Hi.
I don't understand completely your question but i do backups with date on rar.

With rar, the command like this:
[cmd=]/usr/local/bin/rar a -ag_dd-mm-yy_hhmm -r -ep1 -m5 /destination/of/file(bkp).rar /path/to/file[/cmd]
The file.rar will this:
bkp_19-01-10_0304.rar

Name of file and date.

The date command can be represented as:


```
Mon 19 Abr 2010 18:00:00 BRT
```


```
year=`date "+%Y"` = 10
month=`date "+%m"`= 04
day=`date "+%d"` = 19 
hour=`date "+%H"`= 18
minute=`date "+%M"` = 00
```

More details in man date(1).

See ya


----------



## beesatmsu (Apr 27, 2010)

can someone here tell me why my backup script below, somehow erases the log from the day before? (i.e. I only see the current day's backup on the system. it is not a big deal, since I have a script transferring it to another system each day, but i just want to understand why).

backup.sh

```
#!/bin/csh
# backing up wordpress files
cd /usr/backup/xxx
tar cfpj wpress.tar.bz2 /usr/home/wp
mv wpress.tar.bz2  `date +%Y%m%d`WP.tar.bz2
```

a crontab runs the script 4:30 am each day:

```
30 4 * * * /usr/backup/backup.sh >/dev/null 2>&1
```


----------



## jalla (Apr 27, 2010)

beesatmsu said:
			
		

> can someone here tell me why my backup script below, somehow erases the log from the day before? (i.e. I only see the current day's backup on the system. it is not a big deal, since I have a script transferring it to another system each day, but i just want to understand why).
> 
> backup.sh
> 
> ...



The script shown doesn't erase the archive. What's that other script look like?


----------



## beesatmsu (Apr 27, 2010)

my other script simply uses rsync, it should not erase anything either:


```
rsync -avz drone:/usr/backup/xxx /usr/backup/xxx
```


----------



## beesatmsu (Apr 27, 2010)

thus my backup server has:

```
-rw-r--r--  1 xx xx  271950972 Apr 22 04:32 20100422droneWP.tar.bz2
-rw-r--r--  1 xx xx  271950972 Apr 23 04:32 20100423droneWP.tar.bz2
-rw-r--r--  1 xx xx  271950972 Apr 24 04:32 20100424droneWP.tar.bz2
-rw-r--r--  1 xx xx  271950972 Apr 25 04:32 20100425droneWP.tar.bz2
-rw-r--r--  1 xx xx  271950972 Apr 26 04:32 20100426droneWP.tar.bz2
-rw-r--r--  1 xx xx  224057090 Apr 27 04:31 20100427droneWP.tar.bz2
```

but my serve has only one file today:

```
-rw-r--r--  1 xx xx 224057090 Apr 27 04:31 20100427droneWP.tar.bz2
```
and tomorrow it will only have one for April 28. 

strange, eh?


----------



## beesatmsu (Apr 27, 2010)

hmmm, it is possible a wordpress plugin could remove my (one day old) bz2 files, but it is not supposed to remove anything younger than 15 days old...maybe it does not recognize the date if not created by itself...


----------



## jdereus (May 19, 2010)

I copied pieces of my own mysql backup script. there's variable 'NOW" with a date format, and then the database is stored as "$db.$NOW.sql"


```
# Get data in yyyy-mm-dd-HM format
NOW="$(date +"%Y-%m-%d-%Hh%M")"

DBS="$($MYSQL -u $MyUSER -p$MyPASS -Bse 'show databases')"
 
for db in $DBS
do
    skipdb=-1
    if [ "$IGGY" != "" ];
    then
	for i in $IGGY
	do
	    [ "$db" == "$i" ] && skipdb=1 || :
	done
    fi
 
    if [ "$skipdb" == "-1" ] ; then
	FILE="$MBD/$db.$NOW.sql"

    $MYSQLDUMP -u $MyUSER -p$MyPASS $db > $FILE
```


I use this to clean up my database dumps older than 6 days.


```
#!/bin/sh
find /usr/bkp/mysql/daily -mtime +6 -type f -exec rm {} \;
```


----------



## jdereus (May 19, 2010)

Excuse me, I missed the most important part of the backup script 


```
$MYSQLDUMP -u $MyUSER -p$MyPASS $db > $FILE
```


----------



## chuckbuck (May 19, 2010)

Manpage is your friend. 

Don't expect others to write the code for you, you need to show some sort of effort and display what you have if any. With that said, I'll throw you a bone, look up "man date"


----------



## hydra (May 20, 2010)

Maybe try rsnapshot, it is based on rsync.


----------

