Mar
28

Preserve created and modified information when importing a document in SharePoint.

I’m currently writing a web service on our SharePoint server to upload documents because one of our clients would like to migrate from a third party document management system to SharePoint.

This client would like to keep the legacy dates like the date of creation and the last modified date. After researching this, I still couldn’t find a way to do this. I noticed there are tools out there are able to do this so it is definitely possible.

So after some more trial and error I finally figured it out. And it wasn’t even that exotic, so I’d like to share how it is done.

When you’ve uploaded the file and checked it in you can change the dates with the following code:

public void UpdateFileDates(
string siteCollectionUrl, string site, 
string file, DateTime created, DateTime modified)
{
    if (siteCollectionUrl == null) 
       throw new ArgumentNullException("siteCollectionUrl");
 
    using (var spSite = new SPSite(siteCollectionUrl))
    using (var web = string.IsNullOrEmpty(site)
                        ? spSite.RootWeb
                        : spSite.OpenWeb(site))
    {
        var spFile = web.GetFile(file);
        if (spFile != null)
        {
            spFile.CheckIn("");
            var item = spFile.Item;
 
            if (item != null)
            {
            item["Created"] = created;
            item["Modified"] = modified;
 
            spFile.CheckOut();
            item.Update();
            //When you do overwritecheckin the 
	   // version doesn't change.
            spFile.CheckIn("", SPCheckinType.OverwriteCheckIn);
            }
        }
    }
}
Posted by Wim De Coninck | 1 Comment

Mar
09

VMware ESX - Getting rid of disk-space hungry snapshots

Getting rid of disk-space hungry snapshots on VMware Server isn't  really a push-button task and requires a bit of creativity. If you make a snapshot on a production vm in your virtual infrastructure, don't keep it much longer than a day or two at the most. The snapshot will grow automatically to a max of the original vmdk.

http://virtrix.blogspot.com/2006/11/vmware-how-big-can-vm-snapshots-grow.html

Remove a snapshot is easy, right? Sure.... till the task times out.

http://blog.frode.org/?tag=remove-snapshot

The vmdk snapshot file for the VM had grown to several GB’s. Think twice before you press the “delete all” button. When you hit that button, all the snapshots will merge into the original “flat.vmdk”-file  and afterwards all snapshots are deleted.

http://www.yellow-bricks.com/2008/01/07/delete-all-snapshots/

This action takes a while and there are a lot of strange things/problems in VirtualCenter e.g. “VirtualCenter shows no snapshot but it still exist in the ESX under the VirtualMachine directory on the datastore”, VM’s get stuck,… So before you make and remove snapshots, try to understand how a snapshot works and which files are involved:

http://www.virtualizationtrainings.com/vmware-advanced-study/all-about-snapshots-in-vmware-vi3
<machine name>-SnapshotX.vmsn (Where X is the number of the snapshot taken) This file stores the state of the virtual machine when the snapshot was taken.

<machine name>-SnapshotX.vmem (Where X is the number of the snapshot taken) This file stores the state of the virtual machine memory when the snapshot was taken.

<machine name>-n.vmdk (where n is the number of the disk image)

If you want to remove snapshots, never use the snapshotmanager if you want to relax that day!

http://professionalvmware.com/2009/01/19/removing-vmware-snapshots-with-a-bat-powershell-cli-rcli/

Snapshots get stuck, like glue, to a running VM, and despite your best effort to delete them, they won’t go away. Like in-laws, they stick around, a bit longer than is pleasant. If a snapshot has not been removed cleanly on the first try, you may want to create a new snapshot first (just to make sure the system knows there IS a snapshot present) before using the methods below.

Here are a few ways of getting rid of the ones that don’t want to go away:

From the Service Console (ESX)

[root@esx esx:storage1]# vmware-cmd ./VMname/VMname.vmx removesnapshots removesnapshots() = 1

From PowerShell

PS C:\> get-vm VMname* | get-snapshot | Remove-Snapshot -Confirm:$false

Using the rCLI

Install RCLI on a virtualcenter machine

Probably you get an error about a library: http://theether.net/kb/100062

add “C:\Program Files\VMware\VMware VI Remote CLI\Perl\bin” to path environments

C:\Program Files\VMware\VMware VI Remote CLI\bin>vmware-cmd.pl -H esx -U root –P  password /vmfs/volumes/esx:storage1/VMname/VMname.vmx removesnapshots removesnapshot () = 1

Using the Perl Toolkit

./snapshotmanager.pl –server your.vc.host –operation removeall –vmname some.bad.vm

I used the Perl Toolkit (it’s installed with RCLI):

C:\Program Files\VMware\VMware VI Remote CLI\Perl\apps\vm>snapshotmanager.pl -server EsxServer.arfyes.com -operation removeall -vmname VMname

Enter username: root
Enter password:

Warning: depending on the size of the snapshot, it may take a LONG while for them to go away! You can get an idea of how long it’s going to take by looking at how large the snapshots are with ls -lh and note the size of your largest snapshots.

Posted by Lieven Meys | Leave your feedback

Contact us - Raas Van Gaverestraat 83, 9000 Gent, Belgium - Tel. +32 (9) 330.15.00 - Privacy Statement - Sitemap - Sign In Developed with Microsoft Office SharePoint Server 2007