Do you like to see a post on Facebook with emotion or special characters? They will make your post more attractive. Especially if you want to promote your post in a marketing campaign.
Below is list of fantastic characters that you can use:
1. Miscellaneous
☻ ♦ ♣ ♠ ♥ ♂ ♀ ♪ ♫ ☼ ✿ ⊰ ⊱ ✪ ✣ ✤ ✥ ✦ ✧ ✩ ✫ ✬ ✭ ✯ ✰ ✱ ✲ ❃ ❂ ❁ ❀ ✿ ✶ ❉ ❋ ❖ ⊹⊱✿ ✿ ⊰ ⊹ ☆ 🐵 🏪 🍉 👵 👒 🎢 🎈 🐘 💠 😢 🎅 👏 ☝ 💣 🍴 🆒 😌 👲 📡 ☚ 웃 유 ☠ ☯ ☢ ☣ Σ π Ω ♤ ♧ ♡ ♢ ☦ ✞ ⌘ ✡ ✄ ✐ ∞ ▲ ▼ ◎ ☭ 卐 ☪ ™ ¿ ¡ ½ ⅓ ⅔ ¼ № ❝ ❞ ❖ ⚔ ⚖ ⚛ ♲ ⚤ ¶ § ✱ ✲ ❊ ❋ ✻ ✼ ✽ ✵ ✺ ❃ ❅ ❆ ᔓ ᔗ҉ ✾ ❀ ❁ ✿ ⢏ ★ ☆ ✡ ✩ ❂ ✪ ✫ ✬ ✭ ✮ ✯ ✰ ✶ ✷ ✸ ✹
☏ ☠ ☢ ☤ ☪ ✎ ✐ ✑ ✆ ☃ ☄ ☂ ⍭ ☣ ☫ ☬ ☭ ☮ ✇ ☯ ☸
2. Love
❥ ❣ ♡ ღ ❦ ♂ ♀ 웃 유
3. Stars & Flowers
✪ ✩ ✰ ✫ ✬ ✭ ★ ⋆ ✢ ✣ ✤ ✥ ❋ ✦ ✧ ✱ ✶ ✷ ✸ ✺ ✻ ❈ ❉ ❊ ✽ ✾ ✿ ❁ ❃ ❋ ❀
4. Weather
☼ ❅ ☃ ℃ ℉ ϟ
5. Chess
♚ ♛ ♜ ♝ ♞ ♟ ♔ ♕ ♖ ♗ ♘ ♙
6. Cards
♠ ♣ ♥ ♦ ♤ ♧ ♡ ♢
7. Random
ツⓛ ⓞ ⓥ ⓔ ♡ ღ ☼★ ٿ « » ۩ ║ █ ●
8. Religion
回 ₪ ✕ 卐 ☣ ☤ ☥ ☧ ☨ ☩ ☪ ☫ ☬ ☭
9. Music
♫ ♪ ♪ ♫
10. Telephone
✆ ☏
11. Arrows
⏎ ➟ ➢ ➣ ➤ ➥ ➦ ➧ ➨ ➚ ➘ ➙ ➛ ➜ ➝ ➞ ➸ ➲ ➴ ➵ ➶ ➷ ➸ ➹ ➺ ➻ ➼ ➽ ← ↑ → ↓ ↔ ↚ ↛ ↜ ↝ ↞ ↟ ↠ ↡ ↢ ↣ ↤ ↥ ↦ ↧ ↨ ➫ ➬ ➩ ➪ ➭ ➮ ➯ ➱ ↫ ↬ ↭ ↮ ↯ ↰ ↱ ↲
12. Hands
☜ ☞ ☟
13. Numbers
❶❷❸❹❺❻❼❽❾❿
➀➁➂➃➄➅➆➇➈
14. Copyright
Ⓐ © ®
15. Check / tick
✘ ☒ ✓
16. Money
[̲̅$̲̅(̲̅2οο̲̅)̲̅$̲̅] [̲̅$̲̅(̲̅ιοο̲̅)̲̅$̲̅] [̲̅$̲̅(̲̅5̲̅)̲̅$̲̅] [̲̅$̲̅(̲̅1̲̅)̲̅$̲̅]
17. Facemoji
You can use facemoji (a free extension on chrome) for getting other beautiful characters / stickers.
After you installing this extension, your Facebook chat box will have new broken heart icon like below:
Click it to open a windows with many beautiful characters, click to insert into the chat book. Or you can copy and paste to other post on Facebook.
Let enjoy your post on Facebook. Welcome any comment!
Thursday, February 18, 2016
Wednesday, February 17, 2016
Learn ionic and cordova via Facebook login sample
Inherit from the ionic tutorial of ccoenraets and ngOpenFB of r-wettstaedt, this article will walk you through an example on using ionic and ngOpenFB to create an application with Facebook login.
1. To prepare your ionic environment, you can read my article here or follow step 1 of the tutorial of ccoenraets.
2. Create an ionic application with sidemenu template, for example:
# ionic start TestFBLogin sidemenu
You can have a look on the application (TestFBLogin) by run the following commands:
# cd TestFBLogin
# ionic serve
3. Create Film service to query films from https://swapi.co/ (The Star Wars API):
+In the www/js directory, create a file named services.js
+In services.js, define a module named starter.services with a dependency on ngResource. In that module, define a service named Film that uses the Angular resource module to provide access to the REST services at the specified endpoint:
angular.module('starter.services', ['ngResource'])
.factory('Film', function ($resource) {
return $resource(
'http://swapi.co/api/films/:filmId', //url
{}, // query parameters
{'query': { method: 'GET', isArray: false }} //action
);
});
+Open index.html, add a script tag <script src="lib/ionic/js/angular/angular-resource.min.js"></script> to include angular-resource.min.js (right after ionic-bundle.js) and a script tag <script src="js/services.js"></script> to include the services.js file you just created (right after app.js):
4. Create FilmsCtrl controller to manage films list view and FilmCtrl to manage film detail view, open www/js/controllers.js:
+Add starter.services as a dependency to make the Film service available to the controllers:
angular.module('starter.controllers', ['starter.services'])
+Delete PlayListsCtrl (plural), replace it with a controller named FilmsCtrl that retrieves the list of films using the Film service and stores it in a scope variable named films:
.controller('FilmsCtrl', function($scope, Film) {
Film.query(function(data) {
$scope.films = data.results;
});
})
+Delete PlayListCtrl (singular), replace it with a controller named FilmCtrl that retrieves a specific film using the Film service and stores it in a scope variable named film:
.controller('FilmCtrl', function($scope, $stateParams, Film) {
$scope.film = Film.get({filmId: $stateParams.filmId});
});
5. Create 2 templates: films.html to display a list of films, and film.html to display the details of a particular film:
+In the www/templates directory, rename playlists.html (plural) to films.html, then replace by the below template:
<ion-view view-title="Films">
<ion-content>
<ion-list>
<ion-item ng-repeat="film in films | orderBy: 'release_date'"
href="#/app/films/{{$index + 1}}">{{film.title}}</ion-item>
</ion-list>
</ion-content>
</ion-view>
Note:
I use $index to work around because a film doesn't have any property for indexing, it only has url property which causes difficult to get film detail info in next steps.
+ In the www/templates directory, rename playlist.html (singular) to film.html, then replace by the below template:
<ion-view view-title="Film">
<ion-content>
<div class="list card">
<div class="item">
<h2>{{film.title}}</h2>
<p>Released: {{film.release_date}}</p>
<p>Director: {{film.director}}</p>
</div>
<div class="item item-body">
<p>{{film.opening_crawl}}</p>
</div>
<div class="item tabs tabs-secondary tabs-icon-left">
<a class="tab-item">
<i class="icon ion-thumbsup"></i>
Like
</a>
<a class="tab-item">
<i class="icon ion-chatbox"></i>
Comment
</a>
<a class="tab-item">
<i class="icon ion-share"></i>
Share
</a>
</div>
</div>
</ion-content>
</ion-view>
6. Create routes, open app.js in www/js and do as below:
+Replace the app.playlists state with an app.films state defined as the following:
.state('app.films', {
url: "/films",
views: {
'menuContent': {
templateUrl: "templates/films.html",
controller: 'FilmsCtrl'
}
}
})
+Replace the app.single state with an app.film state defined as the following:
.state('app.film', {
url: "/films/:filmId",
views: {
'menuContent': {
templateUrl: "templates/film.html",
controller: 'FilmCtrl'
}
}
});
+Modify the fallback route to default to the list of films (last line in app.js):
$urlRouterProvider.otherwise('/app/films');
+Modify the side menu, open menu.html in www/templates, change the Playlists menu item to below (modify both the item label and the href):
<ion-item menu-close href="#/app/films">
Films
</ion-item>
+You can test again this new modification to see the list of films, here is mine:
7. Now it's time to add ngOpenFB to the application:
+Follow Step 1 here to configure your Facebook App
+To install ngOpenFB to your application, run the command:
# bower install ngOpenFB
+Install the InAppBrowser plugin by cordova:
# cordova plugin add cordova-plugin-inappbrowser
+Move www/lib/ngOpenFB/oauthcallback.html to www/oauthcallback.html
+Open www/index.html, add script tags to include ngOpenFB.min.js (before app.js):
<script src="lib/ngOpenFB/ngOpenFB.min.js"></script>
+Open www/js/app.js, and add ngOpenFB as a dependency to the starter module:
angular.module('starter', ['ionic', 'starter.controllers', 'ngOpenFB'])
+In www/js/app.js, inject $openFB in the run() function declaration:
.run(function ($ionicPlatform, $openFB) {
+Call the $openFB.init() function and set your Facebook App ID in the first line of run() function:
$openFB.init( {appId: '<YOUR_APP_ID>'} );
8. Add Facebook login:
+Open www/templates/login.html, add a Login with Facebook button right after the existing Log In button:
<label class="item">
<button class="button button-block button-positive" ng-click="fbLogin()">
Login with Facebook
</button>
</label>
+Open www/js/controllers.js, and add ngOpenFB as a dependency to the starter.controllers module:
angular.module('starter.controllers', ['starter.services', 'ngOpenFB'])
+Inject $openFB in the AppCtrl controller:
.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $openFB) {
+Add the fbLogin function in the AppCtrl controller (right after the doLogin function):
$scope.fbLogin = function () {
$openFB.login({scope: 'email,public_profile,user_friends'})
.then(function(token) {
// log in successful
console.log('Facebook login succeeded');
$scope.closeLogin();
// send token to your server
}, function(err) {
// error logging in
alert('Facebook login failed');
});
};
9. Display Facebook user profile:
+Create a template for the user profile view. In the www/templates directory, create a new file named profile.html and implement it as follows:
<ion-view view-title="Profile">
<ion-content class="has-header">
<div class="list card">
<div class="item">
<h2>Name: {{user.name}}</h2>
<p>Gender: {{user.gender}}</p>
</div>
<div class="item item-body">
<img src="http://graph.facebook.com/{{user.id}}/picture?width=180&height=180"/>
</div>
</div>
</ion-content>
</ion-view>
+Create a controller for the user profile view. Open www/js/controllers.js, and add the following controller:
.controller('ProfileCtrl', function ($scope, $openFB) {
$openFB.isLoggedIn()
.then(function(loginStatus) {
// if logged, let get user info
$openFB.api({path: '/me'})
.then(function(user) {
$scope.user = user;
}
, function(err) {
alert('Facebook error: ' + err);
});
} , function(err) {
// not logged in
alert('Please use Facebook login!');
});
})
+Create a route for the user profile view. Open www/js/app.js, and add the following route:
.state('app.profile', {
url: "/profile",
views: {
'menuContent': {
templateUrl: "templates/profile.html",
controller: "ProfileCtrl"
}
}
})
+Open www/templates/menu.html, and add the following menu item:
<ion-item menu-close href="#/app/profile">
Profile
</ion-item>
+Let test again your application to see if it works, here is my application in Profile page:
10. Build and test in real device or emulator
+iOS:
# ionic platform add ios
# ionic build ios
# ionic run ios
+Android:
# ionic platform add android
# ionic build android
# ionic run android
Here is my Android version:
You can download its source code from my GitHub.
That's all. Welcome any comments!
1. To prepare your ionic environment, you can read my article here or follow step 1 of the tutorial of ccoenraets.
2. Create an ionic application with sidemenu template, for example:
# ionic start TestFBLogin sidemenu
You can have a look on the application (TestFBLogin) by run the following commands:
# cd TestFBLogin
# ionic serve
3. Create Film service to query films from https://swapi.co/ (The Star Wars API):
+In the www/js directory, create a file named services.js
+In services.js, define a module named starter.services with a dependency on ngResource. In that module, define a service named Film that uses the Angular resource module to provide access to the REST services at the specified endpoint:
angular.module('starter.services', ['ngResource'])
.factory('Film', function ($resource) {
return $resource(
'http://swapi.co/api/films/:filmId', //url
{}, // query parameters
{'query': { method: 'GET', isArray: false }} //action
);
});
+Open index.html, add a script tag <script src="lib/ionic/js/angular/angular-resource.min.js"></script> to include angular-resource.min.js (right after ionic-bundle.js) and a script tag <script src="js/services.js"></script> to include the services.js file you just created (right after app.js):
4. Create FilmsCtrl controller to manage films list view and FilmCtrl to manage film detail view, open www/js/controllers.js:
+Add starter.services as a dependency to make the Film service available to the controllers:
angular.module('starter.controllers', ['starter.services'])
+Delete PlayListsCtrl (plural), replace it with a controller named FilmsCtrl that retrieves the list of films using the Film service and stores it in a scope variable named films:
.controller('FilmsCtrl', function($scope, Film) {
Film.query(function(data) {
$scope.films = data.results;
});
})
+Delete PlayListCtrl (singular), replace it with a controller named FilmCtrl that retrieves a specific film using the Film service and stores it in a scope variable named film:
.controller('FilmCtrl', function($scope, $stateParams, Film) {
$scope.film = Film.get({filmId: $stateParams.filmId});
});
5. Create 2 templates: films.html to display a list of films, and film.html to display the details of a particular film:
+In the www/templates directory, rename playlists.html (plural) to films.html, then replace by the below template:
<ion-view view-title="Films">
<ion-content>
<ion-list>
<ion-item ng-repeat="film in films | orderBy: 'release_date'"
href="#/app/films/{{$index + 1}}">{{film.title}}</ion-item>
</ion-list>
</ion-content>
</ion-view>
Note:
I use $index to work around because a film doesn't have any property for indexing, it only has url property which causes difficult to get film detail info in next steps.
+ In the www/templates directory, rename playlist.html (singular) to film.html, then replace by the below template:
<ion-view view-title="Film">
<ion-content>
<div class="list card">
<div class="item">
<h2>{{film.title}}</h2>
<p>Released: {{film.release_date}}</p>
<p>Director: {{film.director}}</p>
</div>
<div class="item item-body">
<p>{{film.opening_crawl}}</p>
</div>
<div class="item tabs tabs-secondary tabs-icon-left">
<a class="tab-item">
<i class="icon ion-thumbsup"></i>
Like
</a>
<a class="tab-item">
<i class="icon ion-chatbox"></i>
Comment
</a>
<a class="tab-item">
<i class="icon ion-share"></i>
Share
</a>
</div>
</div>
</ion-content>
</ion-view>
6. Create routes, open app.js in www/js and do as below:
+Replace the app.playlists state with an app.films state defined as the following:
.state('app.films', {
url: "/films",
views: {
'menuContent': {
templateUrl: "templates/films.html",
controller: 'FilmsCtrl'
}
}
})
+Replace the app.single state with an app.film state defined as the following:
url: "/films/:filmId",
views: {
'menuContent': {
templateUrl: "templates/film.html",
controller: 'FilmCtrl'
}
}
});
+Modify the fallback route to default to the list of films (last line in app.js):
$urlRouterProvider.otherwise('/app/films');
+Modify the side menu, open menu.html in www/templates, change the Playlists menu item to below (modify both the item label and the href):
<ion-item menu-close href="#/app/films">
Films
</ion-item>
+You can test again this new modification to see the list of films, here is mine:
7. Now it's time to add ngOpenFB to the application:
+Follow Step 1 here to configure your Facebook App
+To install ngOpenFB to your application, run the command:
# bower install ngOpenFB
+Install the InAppBrowser plugin by cordova:
# cordova plugin add cordova-plugin-inappbrowser
+Move www/lib/ngOpenFB/oauthcallback.html to www/oauthcallback.html
+Open www/index.html, add script tags to include ngOpenFB.min.js (before app.js):
<script src="lib/ngOpenFB/ngOpenFB.min.js"></script>
+Open www/js/app.js, and add ngOpenFB as a dependency to the starter module:
angular.module('starter', ['ionic', 'starter.controllers', 'ngOpenFB'])
+In www/js/app.js, inject $openFB in the run() function declaration:
.run(function ($ionicPlatform, $openFB) {
+Call the $openFB.init() function and set your Facebook App ID in the first line of run() function:
$openFB.init( {appId: '<YOUR_APP_ID>'} );
8. Add Facebook login:
+Open www/templates/login.html, add a Login with Facebook button right after the existing Log In button:
<label class="item">
<button class="button button-block button-positive" ng-click="fbLogin()">
Login with Facebook
</button>
</label>
+Open www/js/controllers.js, and add ngOpenFB as a dependency to the starter.controllers module:
angular.module('starter.controllers', ['starter.services', 'ngOpenFB'])
+Inject $openFB in the AppCtrl controller:
.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $openFB) {
+Add the fbLogin function in the AppCtrl controller (right after the doLogin function):
$scope.fbLogin = function () {
$openFB.login({scope: 'email,public_profile,user_friends'})
.then(function(token) {
// log in successful
console.log('Facebook login succeeded');
$scope.closeLogin();
// send token to your server
}, function(err) {
// error logging in
alert('Facebook login failed');
});
};
9. Display Facebook user profile:
+Create a template for the user profile view. In the www/templates directory, create a new file named profile.html and implement it as follows:
<ion-view view-title="Profile">
<ion-content class="has-header">
<div class="list card">
<div class="item">
<h2>Name: {{user.name}}</h2>
<p>Gender: {{user.gender}}</p>
</div>
<div class="item item-body">
<img src="http://graph.facebook.com/{{user.id}}/picture?width=180&height=180"/>
</div>
</div>
</ion-content>
</ion-view>
+Create a controller for the user profile view. Open www/js/controllers.js, and add the following controller:
.controller('ProfileCtrl', function ($scope, $openFB) {
$openFB.isLoggedIn()
.then(function(loginStatus) {
// if logged, let get user info
$openFB.api({path: '/me'})
.then(function(user) {
$scope.user = user;
}
, function(err) {
alert('Facebook error: ' + err);
});
} , function(err) {
// not logged in
alert('Please use Facebook login!');
});
})
+Create a route for the user profile view. Open www/js/app.js, and add the following route:
.state('app.profile', {
url: "/profile",
views: {
'menuContent': {
templateUrl: "templates/profile.html",
controller: "ProfileCtrl"
}
}
})
+Open www/templates/menu.html, and add the following menu item:
<ion-item menu-close href="#/app/profile">
Profile
</ion-item>
+Let test again your application to see if it works, here is my application in Profile page:
10. Build and test in real device or emulator
+iOS:
# ionic platform add ios
# ionic build ios
# ionic run ios
+Android:
# ionic platform add android
# ionic build android
# ionic run android
Here is my Android version:
You can download its source code from my GitHub.
That's all. Welcome any comments!
Friday, December 18, 2015
Quick start your mobile app with Ionic
1. Prepare environment
Read here to install ionic tools. Below is summary
+Install Note.js 4 (Note.js 5 doesn't work)
+Install Ionic by command: $ npm install -g cordova ionic
+Install Ionic lab
+Install bower by command: $ npm install -g bower
+Install VS Code
2. Start a project
2.1 Use command line:
You can create a project with a template as the following:
$ ionic start <<app>> <<template>>
In which:
<<app>>: your app name
<<template>>: a template of ionic, it can be:
Let signup an account on Ionic Creator, then create an app.
After designing your app, click cloud icon to export the code:
There are some ways to export the code as above screen. I prefer IONIC CLI export. When you go there, you will see a command line for you getting code from Ionic Creator to your local pc. Let copy the second command, for example:
$ ionic start [appName] creator:xxxxxxxx
Let replace [appName] by your app name wanted.You may be required to login, key:
$ ionic login
Then provide your user name and password to login Ionic Creator.
3. Edit, run and debug
To open the code in Visual Studio Code (VSC), go to the folder created by the command in step 2. (above), then right click select Open with Code (Windows PC) OR open VSC then open the created folder on Mac or Linux.
Open a html template, you can see many ion- elements, for example <ion-view>. These are custom directives that are part of the Ionic Framework and these directives allow AngularJS to attach behaviour to them. Read more about the Ionic custom directives in the API documentation.
To run your app on the browser, in the folder of your app, run the command:
$ ionic serve
To see what it looks like on iOS and Android, use command:
$ ionic serve --lab
Another way is you can use Ionic Lab application to load your app then run and see.
Read here to install ionic tools. Below is summary
+Install Note.js 4 (Note.js 5 doesn't work)
+Install Ionic by command: $ npm install -g cordova ionic
+Install Ionic lab
+Install bower by command: $ npm install -g bower
+Install VS Code
2. Start a project
2.1 Use command line:
You can create a project with a template as the following:
$ ionic start <<app>> <<template>>
In which:
<<app>>: your app name
<<template>>: a template of ionic, it can be:
- blank: blank project
- maps: project using Google Maps and a side menu
- tabs: project using a simple tabbed interface
- sidemenu: project using a side menu with navigation in the content area
- salesforce: project using for Salesforce
- tests: a test project with different kinds of page navigation
- complex-list: project using a complex list
Let signup an account on Ionic Creator, then create an app.
After designing your app, click cloud icon to export the code:
There are some ways to export the code as above screen. I prefer IONIC CLI export. When you go there, you will see a command line for you getting code from Ionic Creator to your local pc. Let copy the second command, for example:
$ ionic start [appName] creator:xxxxxxxx
Let replace [appName] by your app name wanted.You may be required to login, key:
$ ionic login
Then provide your user name and password to login Ionic Creator.
3. Edit, run and debug
To open the code in Visual Studio Code (VSC), go to the folder created by the command in step 2. (above), then right click select Open with Code (Windows PC) OR open VSC then open the created folder on Mac or Linux.
A Ionic project will have a structure like below:
+www: main folder containing source code
+www/index.html: index html file where the code start
+js: JavaScript folder
+js/app.js: Ionic Starter App (angular starter module)
+js/router.js: AngularUI Router
+templates: folder containing html templates
To run your app on the browser, in the folder of your app, run the command:
$ ionic serve
To see what it looks like on iOS and Android, use command:
$ ionic serve --lab
Another way is you can use Ionic Lab application to load your app then run and see.
Ionic Lab basically is built on top of Chrome which supports LiveReload. So it can help you run and debug your app.
Hope this article can help you start coding with ionic.
Any comment is welcome!
Any comment is welcome!
Friday, November 27, 2015
MS SQL 2014 Mirroring and Trouble Shooting
Below are steps to configure mirroring for a MS SQL Database, and how to use mirroring database in an effective way:
1. Use SQL Management Studio to check if database is in Full Recovery model. If not, let configure it as Full Recovery.
2. Issue a full backup of the database, for example:
BACKUP DATABASE [DBNAME] TO DISK = 'E:\DBNAME.bak';
3. Issue a transaction log backup of the database, for example:
BACKUP LOG [DBNAME] TO DISK = 'E:\DBNAME.trn';
4. Restore the full backup to the Mirror server with the NORECOVERY option. You can use SQL Management Studio to do this, or use a command as below:
RESTORE DATABASE [DBNAME] FROM DISK = 'Z:\DBNAME.bak' WITH NORECOVERY
In the case you want to move files on Mirror server to other folder path differing with folder path on Principal server, you should do as the following:
RESTORE DATABASE [DBNAME] FROM DISK = 'Z:\DBNAME.bak' WITH NORECOVERY,
MOVE 'Logical_Data' TO 'C:\NewPath\DBNAME.mdf',
MOVE 'Logical_Log' TO 'C:\NewPath\DBNAME_log.ldf'
You can know Logical_Data and Logical_Log of the database on Principal server by run a command in step 18.
5. In Mirror server, restore log backup also with the NORECOVERY option, for example:
RESTORE LOG [DBNAME] FROM DISK = 'Z:\DBNAME.trn' WITH FILE=1, NORECOVERY
If you have any auto backup log in Principal server, you should turn off it. Otherwise having any additional log backups before you start mirroring, you must also restore all of those log backups, in sequence (FILE=2, FILE=3 etc.), to the mirror server using WITH NORECOVERY.
6. Configure IPs and host name between 2 servers. On each server open file:
C:\Windows\System32\drivers\etc\host with Administrator right then add a line with IP to point the partner host name, for example:
192.168.72.100 PARTNER_HOST_NAME
To know the host name, open CMD then run command hostname, for example:
C:\Users\Administrator>hostname
7. Configure firewall (inbound port) of each server to allow the port used for this mirroring (e.g. 5022)
8. Configure to allow principal server access SQL on mirroring server. For example, you open port 1433 for principal server.
9. If server instances (mirroring instance & principal instance) are running under different domain user accounts, you should create a same login user for running these instances. This login user can be a Windows user.
In the case both servers are not running on same domain and your servers' names are not in FQDN, you can skip this step and just do the following steps (10, 11, 12, 13).
10. Create a certificate and an endpoint on Principal server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'your_password'
GO
CREATE CERTIFICATE Principal_cert
WITH SUBJECT = 'Principal certificate',
START_DATE = '01/01/2015',
EXPIRY_DATE = '01/01/2050'
GO
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Principal_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GO
BACKUP CERTIFICATE Principal_cert
TO FILE = 'Z:\Principal_cert.cer'
GO
11. Create a certificate and an endpoint on Mirror server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'your_passport'
GO
CREATE CERTIFICATE Mirroring_cert
WITH SUBJECT = 'Mirroring certificate',
START_DATE = '01/01/2015',
EXPIRY_DATE = '01/01/2050'
GO
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Mirroring_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GO
BACKUP CERTIFICATE Mirroring_cert
TO FILE = 'Z:\Mirroring_cert.cer';
GO
12. Create a user login for the endpoint on Principal server:
USE master
GO
CREATE LOGIN Mirroring_login WITH PASSWORD = 'your_password'
GO
CREATE USER Mirroring_user FOR LOGIN Mirroring_login
GO
CREATE CERTIFICATE Mirroring_cert
AUTHORIZATION Mirroring_user
FROM FILE = 'Z:\Mirroring_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Mirroring TO [Mirroring_login]
GO
13. Create a user login for the endpoint on Mirror server:
USE master
GO
CREATE LOGIN Principal_login WITH PASSWORD = 'your_password'
GO
CREATE USER Principal_user FOR LOGIN Principal_login
GO
CREATE CERTIFICATE Principal_cert
AUTHORIZATION Principal_user
FROM FILE = 'Z:\Principal_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Mirroring TO [Principal_login]
GO
14. Use SQL Management Studio to set up Mirroring (partners) for your database on Principle server. Then start your mirroring.
For more quickly, you can user the following commands on the mirror then the principal:
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Principal_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GRANT CONNECT ON ENDPOINT::Mirroring TO [Mirroring_login]
On Mirror server, we can do nothing.
To check existing certificates, run:
SELECT * FROM sys.certificates
15.3 If you want to redo all, let drop all on each server then do above steps again.
USE master
DROP ENDPOINT Mirroring
DROP CERTIFICATE Principal_cert
DROP CERTIFICATE Mirroring_cert
or check state, stop and start:
SELECT * FROM sys.endpoints
ALTER ENDPOINT endpoint_name STATE = STOPPED
ALTER ENDPOINT endpoint_name STATE = STARTED
17. To manually bring mirroring database online after principal database is down use below commands:
FROM sys.master_files
WHERE DB_NAME(database_id) = 'DBNAME'
19. Let create full log backup for principal database for every 15 minutes, if not the log of principal database will increase quickly. In the case of the disk is getting full and you want to shrink log file to free unused space, let restart principal server then run Shrink log file.
That's all. Bye! Any comments is welcome.
1. Use SQL Management Studio to check if database is in Full Recovery model. If not, let configure it as Full Recovery.
2. Issue a full backup of the database, for example:
BACKUP DATABASE [DBNAME] TO DISK = 'E:\DBNAME.bak';
3. Issue a transaction log backup of the database, for example:
BACKUP LOG [DBNAME] TO DISK = 'E:\DBNAME.trn';
4. Restore the full backup to the Mirror server with the NORECOVERY option. You can use SQL Management Studio to do this, or use a command as below:
RESTORE DATABASE [DBNAME] FROM DISK = 'Z:\DBNAME.bak' WITH NORECOVERY
In the case you want to move files on Mirror server to other folder path differing with folder path on Principal server, you should do as the following:
RESTORE DATABASE [DBNAME] FROM DISK = 'Z:\DBNAME.bak' WITH NORECOVERY,
MOVE 'Logical_Data' TO 'C:\NewPath\DBNAME.mdf',
MOVE 'Logical_Log' TO 'C:\NewPath\DBNAME_log.ldf'
You can know Logical_Data and Logical_Log of the database on Principal server by run a command in step 18.
5. In Mirror server, restore log backup also with the NORECOVERY option, for example:
RESTORE LOG [DBNAME] FROM DISK = 'Z:\DBNAME.trn' WITH FILE=1, NORECOVERY
If you have any auto backup log in Principal server, you should turn off it. Otherwise having any additional log backups before you start mirroring, you must also restore all of those log backups, in sequence (FILE=2, FILE=3 etc.), to the mirror server using WITH NORECOVERY.
6. Configure IPs and host name between 2 servers. On each server open file:
C:\Windows\System32\drivers\etc\host with Administrator right then add a line with IP to point the partner host name, for example:
192.168.72.100 PARTNER_HOST_NAME
To know the host name, open CMD then run command hostname, for example:
C:\Users\Administrator>hostname
7. Configure firewall (inbound port) of each server to allow the port used for this mirroring (e.g. 5022)
Can use PsPing for checking port.
8. Configure to allow principal server access SQL on mirroring server. For example, you open port 1433 for principal server.
9. If server instances (mirroring instance & principal instance) are running under different domain user accounts, you should create a same login user for running these instances. This login user can be a Windows user.
In the case both servers are not running on same domain and your servers' names are not in FQDN, you can skip this step and just do the following steps (10, 11, 12, 13).
10. Create a certificate and an endpoint on Principal server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'your_password'
GO
CREATE CERTIFICATE Principal_cert
WITH SUBJECT = 'Principal certificate',
START_DATE = '01/01/2015',
EXPIRY_DATE = '01/01/2050'
GO
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Principal_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GO
BACKUP CERTIFICATE Principal_cert
TO FILE = 'Z:\Principal_cert.cer'
GO
11. Create a certificate and an endpoint on Mirror server:
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'your_passport'
GO
CREATE CERTIFICATE Mirroring_cert
WITH SUBJECT = 'Mirroring certificate',
START_DATE = '01/01/2015',
EXPIRY_DATE = '01/01/2050'
GO
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Mirroring_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GO
BACKUP CERTIFICATE Mirroring_cert
TO FILE = 'Z:\Mirroring_cert.cer';
GO
12. Create a user login for the endpoint on Principal server:
USE master
GO
CREATE LOGIN Mirroring_login WITH PASSWORD = 'your_password'
GO
CREATE USER Mirroring_user FOR LOGIN Mirroring_login
GO
CREATE CERTIFICATE Mirroring_cert
AUTHORIZATION Mirroring_user
FROM FILE = 'Z:\Mirroring_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Mirroring TO [Mirroring_login]
GO
13. Create a user login for the endpoint on Mirror server:
USE master
GO
CREATE LOGIN Principal_login WITH PASSWORD = 'your_password'
GO
CREATE USER Principal_user FOR LOGIN Principal_login
GO
CREATE CERTIFICATE Principal_cert
AUTHORIZATION Principal_user
FROM FILE = 'Z:\Principal_cert.cer'
GO
GRANT CONNECT ON ENDPOINT::Mirroring TO [Principal_login]
GO
14. Use SQL Management Studio to set up Mirroring (partners) for your database on Principle server. Then start your mirroring.
For more quickly, you can user the following commands on the mirror then the principal:
USE MASTER
GO
ALTER DATABASE [DBANME] SET PARTNER = 'TCP://PrincipalServer:5022'
GO
USE MASTER
GO
ALTER DATABASE [DBNAME] SET PARTNER = 'TCP://MirrorServer:5022'
GO
If you see the status "Synchronized", that means everything goes well. If not, the status may be "Suspended". In that status, you need to clean on mirrored server for getting more space then click Resume button here to start the mirroring again.
15. In case of you removed the mirroring for maintaining / cleaning DB on principal, after removing mirorring you can do step 2, 3, 4, 5 to update new DB to the mirror server. Then you can start the mirroring again by one of the following ways:
15.1 Start the mirroring session again by running below commands:
First on the mirror:
15. In case of you removed the mirroring for maintaining / cleaning DB on principal, after removing mirorring you can do step 2, 3, 4, 5 to update new DB to the mirror server. Then you can start the mirroring again by one of the following ways:
15.1 Start the mirroring session again by running below commands:
First on the mirror:
ALTER DATABASE [DBNAME] SET PARTNER OFF
ALTER DATABASE [DBNAME] SET PARTNER = N'TCP://PrincipalServer:5022'
Then on the principal:
ALTER DATABASE [DBNAME] SET PARTNER = N'TCP://MirrorServer:5022'
15.2 Recreate ENDPOINT for the mirroring, let drop it on Principal server and create again.
DROP ENDPOINT Mirroring
ALTER DATABASE [DBNAME] SET PARTNER = N'TCP://PrincipalServer:5022'
Then on the principal:
ALTER DATABASE [DBNAME] SET PARTNER = N'TCP://MirrorServer:5022'
15.2 Recreate ENDPOINT for the mirroring, let drop it on Principal server and create again.
DROP ENDPOINT Mirroring
CREATE ENDPOINT Mirroring
STATE = STARTED
AS TCP (LISTENER_PORT = 5022, LISTENER_IP = ALL)
FOR DATABASE_MIRRORING
(
AUTHENTICATION = CERTIFICATE Principal_cert,
ENCRYPTION = REQUIRED ALGORITHM AES,
ROLE = ALL
)
GRANT CONNECT ON ENDPOINT::Mirroring TO [Mirroring_login]
On Mirror server, we can do nothing.
To check existing certificates, run:
SELECT * FROM sys.certificates
15.3 If you want to redo all, let drop all on each server then do above steps again.
USE master
DROP ENDPOINT Mirroring
DROP CERTIFICATE Principal_cert
DROP CERTIFICATE Mirroring_cert
DROP LOGIN [login]
DROP USER [user]
DROP MASTER KEY
DROP MASTER KEY
GO
16. To check whether a server instance has a database mirroring endpoint and to learn its role and state, on that instance, use the following Transact-SQL statement:
SELECT * FROM sys.database_mirroring_endpoints
or
SELECT role_desc, state_desc FROM sys.database_mirroring_endpoints
16. To check whether a server instance has a database mirroring endpoint and to learn its role and state, on that instance, use the following Transact-SQL statement:
SELECT * FROM sys.database_mirroring_endpoints
SELECT role_desc, state_desc FROM sys.database_mirroring_endpoints
or check state, stop and start:
SELECT * FROM sys.endpoints
ALTER ENDPOINT endpoint_name STATE = STOPPED
ALTER ENDPOINT endpoint_name STATE = STARTED
17. To manually bring mirroring database online after principal database is down use below commands:
ALTER DATABASE [DBNAME] SET PARTNER OFF
RESTORE DATABASE [DBNAME] WITH RECOVERY
18. To use mirroring database any time (e.g. for your reports), let create snapshot of mirroring database then use it as an independent database.
Firstly, you need know the Logical Name of your mirroring database, run:
SELECT name AS LogicalName, type_desc, physical_nameFirstly, you need know the Logical Name of your mirroring database, run:
FROM sys.master_files
WHERE DB_NAME(database_id) = 'DBNAME'
Then create the snapshot:
CREATE DATABASE [DBNAME_SNAPSHOT_NAME] ON --
(
NAME = 'LogicalName' , FILENAME = 'Z:\DBNAME_SNAPSHOT_NAME.ss' -- replace with the Logical Name above
)
AS SNAPSHOT OF [DBNAME]
(
NAME = 'LogicalName' , FILENAME = 'Z:\DBNAME_SNAPSHOT_NAME.ss' -- replace with the Logical Name above
)
AS SNAPSHOT OF [DBNAME]
19. Let create full log backup for principal database for every 15 minutes, if not the log of principal database will increase quickly. In the case of the disk is getting full and you want to shrink log file to free unused space, let restart principal server then run Shrink log file.
That's all. Bye! Any comments is welcome.
Subscribe to:
Posts (Atom)








