Category Archives: Virtualization

Batch File FTP

call the script with ftp -s:scriptname.txt

Name this scriptname.txt

open 8.8.8.8 21
admin
1234
lcd C:\DatabaseBackups\Data
bin
prompt
mput *.rar

quit

Batch File: compress and separate out large files for ftp

This will compress and split a large database file and ftp it over the internet.
@setlocal
@echo off
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)

Set AFILE=C:\DatabaseBackups\Data\db.bak
Set BFILE=d:\backup\Data
Set LFILE=d:\backup\Logs
set MYDATA=MyDatabasename
set PATH="C:\Program Files\WinRAR";%PATH%

cd c:
cd C:\DatabaseBackups\Data

"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -E -Q "BACKUP DATABASE %MYDATA% TO DISK='%AFILE%'"

echo Y|copy %AFILE% %BFILE%

REM THiS SPLITS THE DATABASE BACKUP FILE INTO 25MB SECTIONS OF A RAR
echo Y|rar a -m5 -v25000k %Year%%Month%%Day% %AFILE%

ftp -s:cescript2.txt
ECHO Y |DEL %AFILE%
ECHO Y |DEL *.RAR

Batch File: get and Separate DATE

use this to separate out the year month and day to variables to use in backup scripts

@setlocal
@echo off
@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)


Then use them like this to create a daily unique filename
mkdir c:\Backup\%Year%\%Month%%Day%
This will create a folder that looks like c:\Backup\2017\0501

XENSERVER Add ISO Storage

This will add Local ISO Storage to the server That youi can then map and copy iso files over to.

mkdir /var/opt/ISO_IMAGES

xe sr-create name-label=ISO_IMAGES_LOCAL type=iso device-config:location=/var/opt/ISO_IMAGES device-config:legacy_mode=true content-type=iso

Then to mount a Windows Server use:
mkdir /mnt/tmp
mount -t cifs //192.168.1.10/ISO /mnt/tmp -o username=administrator

use the following to copy files over
cp -a /mnt/tmp/*.iso /var/opt/ISO_IMAGES

Ubuntu Adding New drive to replace /var

1. First you need some unallocated space to create the partitions for each mountpoint (/var, /home, /tmp). Use Gparted for this.

2. Then you need to create the filesystems for those partitions (can be done with Gparted too) or use:

mkfs.ext4 /dev/sdaX

for example to create a new ext4 filesystem on the /dev/sdaX device (replace /dev/sdaX with your own device)

3. Mount the new filesystem under /mnt

 

mkdir /mnt/var
 mount /dev/sdaX /mnt/var

4. Go to single-user mode so that there is no rw activity on the directory during the process

 

init 1    /* for older ubuntu*/
systemctl isolate multi-user.target   /* for systemd */5. Enter your root password.

6. Backup data in var only (not the /var directory itself)

cd /var
 cp -ax * /mnt/var

7. Rename the /var directory after your data has been transferred successfully.

cd /
 mv /var /var.old

8. Make the new var directory

mkdir /var

9. Unmount the new partition.

umount /dev/sdaX

10. Remount it as /var

mount /dev/sdaX /var

11. Edit /etc/fstab file to include the new partition, with /var being the mount point, so that it will be automatically mounted at boot.

/dev/sdaX /var ext4 defaults 0 0

Repeat all these steps for /home and /tmp.

VB .NET Binary formatter compression to/from file

Saving a file with a binary formatter whether a dataset, datatable or parameterized Object will save lots of space

20,000 well log feet with comments and header: 3857KB with binary formatter alone
20,000 well log feet with comments and header: 551KB with binary formatter with gzip

Public Function LoadFile(settingsFile As String) As Object
Dim ds As New Object
Try
Dim fs As New FileStream(settingsFile, FileMode.Open)
Dim decompressor As New GZipStream(fs, CompressionMode.Decompress)
Dim bf As New BinaryFormatter()
ds = DirectCast(bf.Deserialize(decompressor), Object)
decompressor.Close()
fs.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return ds
End Function


Public Sub WriteFile(d As Object, settingsFile As String)
Dim fs As New FileStream(settingsFile, FileMode.Create)
Dim compressor As New GZipStream(fs, CompressionMode.Compress)

Dim bf As New BinaryFormatter()
bf.Serialize(compressor, d)
compressor.Close()
fs.Close()
End Sub

Using performance Counters

I like to use the memory and CPU counters while away from hardware equipment that we use to read gases and oxygen levels. They provide a real time input for testing and can be used very quickly, easily and the speed can be adjusted to whatever i need it to be.

to use place the following code as class variables in the form or what ever you need to call it.

Dim mem As New System.Diagnostics.PerformanceCounter("Memory", "Available MBytes")
Dim cpu As New System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total")

Then in the timer or calling function use this.

dim M as double = mem.NextValue()
dim C as double = cpu.NextValue()