Tuesday, November 20, 2012

Subversion backup on linux


BACKUP

To make a complete copy of the Subversion repository system just follow these small steps:

- Locate the repository directory, in our case: / var / lib / svn
- Locate the destination directory for the backup, in our case: / tmp /
- Perform a dump of the repository with the following command:

sudo svnadmin dump / var / lib / svn> / tmp / svnbackup.dump

RESTORING BACKUP


After creating a backup to restore, just run the following command:

sudo svnadmin load / var / lib / svn </ tmp / svnbackup.dump
For example, to automate this task attached a small script that can be put in the cron server for convenience when backing up versions of our system:

---- svnbackup.sh ----
#!/bin/sh HORA=$(date +"%Y-%m-%d")
FICHERO="/tmp/svnbackup-$HORA.dump"
REPOSITORIO= /var/lib/svn
svnadmin dump $REPOSITORIO > $FICHERO
---- fin svnbackup.sh ----

MySQL Backup on Linux


BACKUP DATABASE

Mysqldump command examples:

To perform the online backup of the database to the file mydb copia_seguridad.sql

mysqldump --opt mydb > backupfile.sql

Another more complex example of mysqldump to backup a database is as follows:
mysqldump --opt -password=mypassword -user=miuser mydatabase > backupfile.sql

In the latter case we are indicating a user name and password to access the database on which the backup is being done: mydatabase. SQL statements to rebuild that database file will be flushed archivo.sql.

RESTORE DATABASE

If we want to retrieve information from a file to restore a backup of the database will do with the mysql command. We will use a syntax like:

mysql mydb
This example is based restore mydb data stored in the backup file archivo.sql.

Another example of more complex command to restore a database is as follows:


mysql -password=mypassword -user=miuser mydb < backupfile.sql

Hope help!

Wednesday, October 3, 2012

wget to download not accessible whole pages or sites

Hi all,

Today the problem is how to download a whole website for legal proposes. One interesting tool we can use is wget. For example we can write:

$ wget -r URL

to download the site.

Sometime it doesn't work because developers restrict the access of robots, browsers, etc. In this case we are going to receive an error HTML page. Wget allows us to mimic different browsers HTTP headers. For example, an easy way to download this kind of sites is to define an alias:

alias wgets='H="--header"; wget $H="Accept-Language: en-us,en;q=0.5" $H="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" $H="Connection: keep-alive" -U "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2" --referer=http://www.google.com/ '
and then repeat our first command but now adding a "s" after wget:

$ wgets -r URL
There are other tools like curl more powerful as wget for more general proposes.

Have fun!



Sunday, September 23, 2012

Where is my SVN in Mac OS X Mountain Lion?

Well, I've just installed the new OS X Mountain Lion and surprise!!! There is no SVN on it. Subversion is not included in this new version but developers need SVN as well and not only GIT.


How to install it?

If you are a iOS developer you are lucky. After install the last release of XCode go to Preferences > Download > Command Line Tools  and click on Install. Wait a while (115.4MB) and done! You will have SVN installed in your Mac.

Hope Help!



Tuesday, June 19, 2012

Sending files via FTP automatically under LINUX

Hi,

I'm going to show how to send files (backup copies for example) via FTP using ncftp and a traditiona ftp cliente under linux.

NCFTP

First we need to install the ncftp package:

apt-get insttall ncftp

And now the script (script name: sendviaftp.sh) :

#!/bin/bash
FTP_SERV="ftp.yourserver.com"
FTP_USER="youruser"
FTP_PASS="yourpass"
FTP_PATH="/directory/you/want"
ncftpput -R -m -u $FTP_USER - p $FTP_USER $FTP_SERV $FTP_PATH $1

where $1 is the command line parameter. For example:

./sendviaftp.sh   filetosend.tar.gz

FTP Cliente

If you want to do the same with your traditional FTP client the steps are:

1) Add to the file  ~/.netrc the user and password for your FTP
vi ~/.netrc
default login FTPUSERNAME password FTPPASSWORD


2) Write the next script


#!/bin/bash
HOST='ftp.yourserver .com'
ftp  -i $HOST <<END_SCRIPT
put $1
quit
END_SCRIPT
exit 0


3) Try it up:

chmod 0600 ~/.netrc
chmod +x ftpscript
./ftpscript

Bye! 

Sunday, March 11, 2012

Video for iPhone/iPad using MPMoviePlayerController

First of all, we need to add the framework MediaPlayer to the project (MediaPlayer.framework) and then include the header file:
#import <MediaPlayer/MediaPlayer.h>
Suppose we saved the  MP4 file on disk. We have to provide the path in our code:
NSString *path = [[NSBundle mainBundle] pathForResource:@"nombre-video-sin-ext" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:path];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
Now we have to set the video size and position. It is worth noting that MPMoviePlayerController inherits from UIViewController so we set the player.view properties.
player.view.frame = CGRectMake(50, 50, 698, 500);
[self.view addSubview:player.view];
[player prepareToPlay];
Finally, if we want to manage the video we will use:
[player play];
[player pause];
[player stop];
If we want to perform an action when the video ends, we can use notifications. For example:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
y pass the object player as a parameter to the function movieFinishedCallback:
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player autorelease];
}
We are ready to watch videos on iPad or iPhone.