Using Netcat for Backup: Difference between revisions

From RSWiki
Jump to navigation Jump to search
No edit summary
 
m (Quick tidy up.)
Line 3: Line 3:
Providing you have netcat installed, on the destination machine execute the following command:
Providing you have netcat installed, on the destination machine execute the following command:


----
nc -l -p 6666 > filename.tar.bz2
 
''nc -l -p 6666 > filename.tar.bz2''
 
----


This creates a listening socket on port 6666 with the filename specified above.
This creates a listening socket on port 6666 with the filename specified above.
Line 15: Line 11:
So on the source you can issue the following command:
So on the source you can issue the following command:


----
tar jlcvPpf - / > /dev/tcp/192.168.0.2/6666
 
''tar jlcvPpf - / > /dev/tcp/192.168.0.2/6666''
 
----


In the example above 192.168.0.2 is the address of the destination address and the forward slash indicates that it is the entire filesystem to be backed up. You can easily change this for example to ''tar jlcvPpf - /var/www > /dev/tcp/192.168.0.2/6666'' to backup the /var/www directory.
In the example above 192.168.0.2 is the address of the destination address and the forward slash indicates that it is the entire filesystem to be backed up. You can easily change this for example to ''tar jlcvPpf - /var/www > /dev/tcp/192.168.0.2/6666'' to backup the /var/www directory.

Revision as of 08:17, 19 June 2006

Using Netcat for Backup

Providing you have netcat installed, on the destination machine execute the following command:

nc -l -p 6666 > filename.tar.bz2

This creates a listening socket on port 6666 with the filename specified above.

We now need to setup the source machine to dump whatever directories or filesystems you want to send to the destination machine.

So on the source you can issue the following command:

tar jlcvPpf - / > /dev/tcp/192.168.0.2/6666

In the example above 192.168.0.2 is the address of the destination address and the forward slash indicates that it is the entire filesystem to be backed up. You can easily change this for example to tar jlcvPpf - /var/www > /dev/tcp/192.168.0.2/6666 to backup the /var/www directory.

The options for the tar command are as follows:

  • j - do bzip2 compression on the archive
  • l - one file system (more on this later)
  • c - create archive
  • v - be verbose about it
  • P - don't strip leading / from pathnames
  • p - preserve permissions
  • f - the file name to write, which in this case is - which means standard output.